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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -