vendredi 5 février 2016

how to right choose javascript pattern

i create 2 objects:

  var Documentos = new QuadForm();
  var Cadastro = new QuadForm();

And initialize this objects with lot of options

    Cadastro.initForm(options);
    Documentos.initForm(options2);

then i try to separate the data managed by each object with getName method but after the second object, myObjectName variable is overrided.

    var QuadForm;
QuadForm = function () {
    this.getName = function () {
        // search through the global object for a name that resolves to this object
        for (var name in window)
            if (window[name] == this) {
                window[name] = this;
                window[window[name]] = window[name];
                myObjectName= name;
                break;
            }
    },
        this.initForm = function (parms) {

            this.getName()

            $.extend(this, parms);
            if (window.myState) {
                delete window.myState;
            }
            this.containerId = parms.formId;
            this.getForm(parms);
            this.workflowLabels('hide');

then i use window[myObjectName].totalRecords but as it changes to the latest object name off course cannot access data.

How can i manage this.

Aucun commentaire:

Enregistrer un commentaire