标签:fun 构造 obj 怎样 eof class pre creat style
需要使用Object.create()方法.
function Person(name){ this.name = name; } var lilei = new Person("Lilei"); lilei.name; // "Lilei" var hanmeimei = Object.create(lilei); hanmeimei.name; // "Lilei"; lilei.name = "李雷"; hanmeimei.name; // "李雷"; hanmeimei.name = "韩梅梅"; lilei.name; // "李雷"; hanmeimei.name; // "韩梅梅" lilei instanceof Person; // true hanmeimei instanceof Person; // true
上面的代码说明了一个情况, 就是通过Object.create()生成的实例对象尽管是Person的实例对象, 在不手动赋值之前, 它的属性和方法是跟参数对象保持一致的;
标签:fun 构造 obj 怎样 eof class pre creat style
原文地址:https://www.cnblogs.com/aisowe/p/11653770.html