原型链-面向面试

总有人问我面试时候原型链怎么写,

作为一位职场老司机,面试界的白神。身经百战,撸出以下的代码

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>面向面试的原型链</title>
    <link rel="stylesheet" type="text/css" href="">
</head>
<body>
<script>
var interviewer = function(){}
var handsome =function(){}
interviewer.prototype = {}
handsome.prototype = {
    rich : function(){
        console.log('I am very rich')
    },
    handsome:function(){
        console.log('The whole world know that I am handsome ')
    }
}
interviewer.prototype = new handsome;
interviewer.prototype.rich()
interviewer.prototype.handsome()
</script>
</body>
</html>

 怎么样,看懂的是不是觉得以上的代码清新脱俗,焕然一新

没看懂的,在这里解释下

首先我定义了interviewer(面试官)和handsome (英俊)2个函数。

然后给他们2个的原型加了点东西,当然主要是handsome加参数,一个rich,一个是handsome

当然I am very rich是川普的名言。。。比起希拉里,我觉得川普上台当米国总统会很有意思。

川普:“你连你老公都满足不了,如何满足米国人民。”  我觉得是米国最霸气的竞选演讲了

好了,以上打住,最后我们将handsome这个玩意new了一下给了面试官。

 

interviewer.prototype = new handsome;

 

然后高富帅满足了2个条件。。。

 

考虑到每个面试官的身高。。。23333(小四也不一定是个例对吧)

 

原文地址:https://www.cnblogs.com/LoveOrHate/p/5992867.html