Javascript中如何不调用构造函数实例化一个对象?


Javascript中如何不调用构造函数实例化一个对象?

前端 JavaScript

我不是2b 11 years, 2 months ago

你是说实例化一个类吧,对于用户自定义的类,


 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

答案摘自这里

≮ゼロD喵≯ answered 11 years, 2 months ago

Your Answer