javascript - What is gained when you .extend() an obj prototype with itself -
i looking @ code, , make sure wasn't losing mind missing obvious looks me, there nothing gained. seems wasteful usage of $.extend() perhaps can shed light on might missing inheritance.
so, have this.
_letscreatenamespace('us.somenew.obj'); //this based on s.stoyanov namespace pattern, _letscreatenamespace does. then seen in code, , didn't make sense me.
us.somenew.obj = function(){ // var assignments. this.blah = $foo; } // usage of extend escapes me. don't see need @ point here. $.extend(us.somenew.obj.prototype, { // bunch of new methods } i not see @ benefit of using $.extend() instead of following, there no extending itself.
us.somenew.obj.prototype = { // bunch of new methods } there no 'deep' extend or anything.. looks verbose way of extending prototype no reason.
am missing something? there "forest behind tree's" methodology missing here?
$.extend copies prototype methods given without overwrite prototype object itself. instance, if have:
// inheritance us.somenew.obj.prototype = myproto; us.somenew.obj.prototype = { // lost inheritance `myproto`, here } using $.extend prevent that. plus, won't lose default property. example, constructor:
us.somenew.obj = function () {}; us.somenew.obj.prototype = {}; var o = new us.somenew.obj(); console.log(o.constructor === us.somenew.obj) // false, in case `object` where:
us.somenew.obj = function () {}; $.extend(us.somenew.obj.prototype, {}); var o = new us.somenew.obj(); console.log(o.constructor === us.somenew.obj) // true
Comments
Post a Comment