Javascript中如何不调用构造函数实例化一个对象?
5 回答
繁华开满天机
TA贡献1816条经验 获得超4个赞
你是说实例化一个类吧,对于用户自定义的类,
new f(a, b, c)
相当于
// Create a new instance using f's prototype.
var newInstance = Object.create(f.prototype), result;
// Call the function
result = f.call(newInstance, a, b, c),
// If the result is a non-null object, use it, otherwise use the new instance.
result && typeof result === 'object' ? result : newInstance
小唯快跑啊
TA贡献1863条经验 获得超2个赞
function createPeople(name,age){
var o = {};
o.name = name;
o.age = o.age;
return o;
}
var people = createPeople('chen',30);
添加回答
举报
0/150
提交
取消