Created
August 27, 2018 15:52
-
-
Save KScaesar/82c0b26bce4d3a1fa48feb2e23eb2563 to your computer and use it in GitHub Desktop.
javascript Object.create
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Object.create = function (obj) { | |
| var F = function () {}; //1.生成新的建構函數 | |
| F.prototype = obj; //2.連接新建構函數的prototype到obj | |
| return new F(); //3.返回用F製造出來的新物件, | |
| // F為沒有內容的空函數,返回物件的__proto__連接obj | |
| // 返回物件被設為空函數F的this綁定 | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment