原型鏈-面向面試


總有人問我面試時候原型鏈怎么寫,

作為一位職場老司機,面試界的白神。身經百戰,擼出以下的代碼

<!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(小四也不一定是個例對吧)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM