Can I construct a JavaScript object without using the new keyword?

后端 未结 15 2791
北海茫月
北海茫月 2020-11-27 16:04

Here is what I\'d like to do:

function a() {
  // ...
}
function b() {
  //  Some magic, return a new object.
}
var c = b();

c instanceof b // -> true
c          


        
15条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 16:39

    Someone posted an article by douglas crockford in this question, and it explains exactly what your asking.

    OO Javascript constructor pattern: neo-classical vs prototypal

提交回复
热议问题