Skip to content

Instantly share code, notes, and snippets.

@KScaesar
Created August 27, 2018 15:52
Show Gist options
  • Select an option

  • Save KScaesar/82c0b26bce4d3a1fa48feb2e23eb2563 to your computer and use it in GitHub Desktop.

Select an option

Save KScaesar/82c0b26bce4d3a1fa48feb2e23eb2563 to your computer and use it in GitHub Desktop.
javascript Object.create
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