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

后端 未结 15 2759
北海茫月
北海茫月 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 17:00

    What's wrong with using the new keyword?

    At any rate, it sounds like the best thing to do is read up on Javascript inheritance: http://javascript.crockford.com/inheritance.html

提交回复
热议问题