oop - javascript object literal instantiation -


i new js oop , dont understand how can this.

i have

var cadastro = object.create(qform); var options = {     myinstancename: "cadastro",     dependentlistsmode: "one",     defaultbuttons: ['enter-query', 'new'] } cadastro.initform(options); 

then have qform.js

var qform; qform = {     initform: function (parms) {                $.extend(this, parms);                 var frmobj = $(this.formid);         this.userrestrictions(parms);                $(this.currentform).find("a[data-form-action]").hide();         this.clearform();         this.disablefields();     }, 

the problem if have e object in same page , this.currentform have value of latest intantiated object .

qform.js extense file lot of methods. how can manage this. thanks

in general code works, uses object.create create new instances based on qform prototype , new instances not share properties, here short working example:

var qform;  qform = {      initform: function (parms) {                 $.extend(this, parms);                  this.frmobj = $(this.formid);      }  };    var cadastro = object.create(qform);  var options = {      myinstancename: "cadastro",      formid: "cadastroform",      dependentlistsmode: "one",      defaultbuttons: ['enter-query', 'new']  }  cadastro.initform(options);    var formtwo = object.create(qform);  var options = {      myinstancename: "formtwo",      formid: "test",      dependentlistsmode: "one",      defaultbuttons: ['enter-query', 'new']  }  formtwo.initform(options);     alert(cadastro.formid);  alert(formtwo.formid);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

if run it, see cadastroform , test, 2 instances created based on qform have different formid properties.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -