Object.create and Pure Prototypa
作者:
Zihowe | 来源:发表于
2017-08-28 05:44 被阅读10次// polyfill
if (!Object.create) {
Object.create = function (o) {
if (arguments.length > 1) {
throw new Error('Object.create implementation'
+ ' only accepts the first parameter.');
}
function F() {}
F.prototype = o;
return new F();
};
}
var person = {
firstname: 'Default',
lastname: 'Default',
greet: function() {
return 'Hi ' + this.firstname;
}
}
var john = Object.create(person);
john.firstname = 'John';
john.lastname = 'Doe';
console.log(john);
本文标题:Object.create and Pure Prototypa
本文链接:https://www.haomeiwen.com/subject/vnkwdxtx.html
网友评论