Tutorial: Example 1. Simple and Complex Objects

Example 1. Simple and Complex Objects

WrapperTracer - by GuerraTron

Select a object to wrapper:

Simple Objects.   Complex Objects.
//LITERAL OBJECT
var obj1 = {
  tag: "obj1",
  prop1: "uno",
  prop2: 2,
  prop3: true,
  prop4: null,
  prop5: undefined,
  objX: {p1: "p1", p2: 2},
  arrX: ["p1", 2],
  conf: function conf(obj){
    var out="{";
    for(o in obj){
      obj3[o]= obj[o];
      out += o + ": "+obj[o]+", ";
    }
    out += "}";
    return out;
  }
};
              
//THIS FUNCTION RETURNS A OBJECT
var obj2 = function(){
  var _TAG= "obj2";
  var prop1= "uno";
  var prop2= 2;
  this.prop3= true;
  function getProp2(){
    return prop2;
  }
  function conf(obj){
    var out="{";
    for(o in obj){
      obj3[o]= obj[o];
      out += o + ": "+obj[o]+", ";
    }
    out += "}";
    return out;
  }
  //PUBLIC API
  return {
    tag: _TAG,
    prop1: prop1,
    prop2: getProp2,
    prop4: null,
    prop5: undefined,
    objX: {p1: "p1", p2: 2},
    arrX: ["p1", 2],
    meth1: function funcMeth1(param1){ alert(param1); },
    conf: conf
  };
}();
              
//SELF-EXECUTING FUNCTION (WITH CLOSURE) FROM ACCESS 
//RESTRICTED BY THE KEYWORD 'new' (CLASS)
var obj3= (function () {
  var _TAG= "obj3";
  var _prop4= null; //privada
  //constructor
  function obj3(){
    this.tag = "'" + _TAG + "'";
    this.prop1= "uno";
    this.prop2= 2;
    this.prop3= true;
    this.prop44=null;
    this.prop55=undefined;
    this.objX= {p1: "p1", p2: 2};
    this.arrX= ["p1", 2];
    this.meth1= function (param1){
      alert(param1);
    };
  }
  obj3.prototype.prop33= false;
  obj3.prototype.getProp4= function (){
    return _prop4;
  };
  obj3.prototype.prop444= null;
  obj3.prototype.prop5= undefined;
  obj3.prototype.objX2= {p1: "p1", p2: 2};
  obj3.prototype.arrX2= ["p1", 2];
  obj3.prototype.prop6= "uno-uno";
  obj3.prototype.prop7= 22;
  function conf(obj){
    var out="{";
    for(o in obj){
      obj3[o]= obj[o];
      out += o + ": "+obj[o]+", ";
    }
    out += "}";
    return out;
  }
  obj3.prototype.conf= conf;
  //CLOSURE
  return obj3;
})();
              

 



Δ