javascript - Can't explain result of that pattern -
can explain me result of code, don't understand what's happening here..
here code :
var myobj = (function() { var testpatt = function(params) { jquery.extend(this.options, this.defaults, params); }; testpatt.prototype = { constructor : testpatt, options : {}, defaults : {} }; return testpatt; })(); var title1 = new myobj({ "title" : "mon titre" }); var title2 = new myobj({ "title" : "mon titre 2ème edition" }); console.log(title1.options.title) //--> "mon titre 2ème edition"; ???????
i expect console write "mon titre" result "mon titre 2ème edition", can't explain why...
see fiddle
there 1 prototype, , shared between instances.
so each time create new object, "global" options (stored in prototype) overwritten.
Comments
Post a Comment