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
| function Foo(){ | |
| this.testArr=[2,4]; | |
| }; | |
| Foo.prototype={ | |
| str:'test', | |
| num:1, | |
| arr:[1,2], | |
| obj:{a:2} | |
| }; |
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綁定 | |
| }; |
NewerOlder