flaw2398x44

Benchmark created on


Setup

// Regular constructor
    var conPerson = function(name, lastName) {
        
        this._name = name;
        this._lastName = lastName;
        this._address = null;
        this._phone = null;
        
        this.setAdress = function(address) {
                this._address = address;
        };
        
        this.setPhone = function(phone) {
                this._phone = phone;
        };
        
        this.toString = function() {
                console.log('[Person]: ' + this._name + ' ' + this._lastName + '\n[Address]: ' + this._address + '\n[Phone]: ' + this._phone);
        };
        
    };
    
    // Literal
    var lPerson = {
        _name: '',
        _lastName: '',
        _address: '',
        _phone: '',
        init: function (name, lastName) {
                this._name = name;
                this._lastName = lastName;
                
                return this;
        },
        setAdress: function(address) {
                this._address = address;
        },
        setPhone: function(phone) {
                this._phone = phone;
        },
        toString: function() {
                console.log('[Person]: ' + this._name + ' ' + this._lastName + '\n[Address]: ' + this._address + '\n[Phone]: ' + this._phone);
        }
    };
    
    
    
    var heranca1 = function(){
    
        conPerson.apply(this);
    
    }
    
    
    
    var heranca2 = function(){
    
    }
    
    heranca2.prototype = lPerson;
    
    
    var heranca3 = function(){
    }
    
    heranca3.prototype = new conPerson();

Test runner

Ready to run.

Testing in
TestOps/sec
heranca1
var h1 = new heranca1();
h1.setAdress("law");
h1.setPhone(222);
ready
heranca2
var h2 = new heranca2();
h2.setAdress("law");
h2.setPhone(222);
ready
heranca3
var h3 = new heranca3();
h3.setAdress("law");
h3.setPhone(222);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.