1

failing to effectively implement the elusive prototype concept, I found myself extending objects like this:

function BaseObj(propertyA){
    var obj = {
        baseProperty: propertyA,
        baseMethod: function(){ 
            //doStuff.. 
        }
    return obj;
}

function BiggerObj(propertyA, propertyB){
    var obj = BaseObj(propertyA);
    obj.anotherProperty = propertyB;
    obj.anotherMethod = function(){ 
        //doOtherStuff.. 
    };
}

this way of extending objects turned out to be really comfortable and I started getting long chains of this kind of inheritance hirarcy. my question to those who do understand the prototype model: is there a core difference between dealing with the prototype chain and extending objects like the above method?
are there things that you can do with the prototype that u can't do like this?

Ido Ofir
  • 207
  • 2
  • 8
  • 5
    `biggerObjInstance instanceof BaseObj` would give you false. Also, you are not sharing any data between instances (like functions) so you end up using more memory if you have many instances than with prototype inheritance. – Felix Kling Oct 25 '12 at 01:09
  • @Felix: Can you point to any good articles or other resources that expand a bit more on your second point? – Kevin Boucher Oct 25 '12 at 01:14
  • 1
    http://stackoverflow.com/questions/310870/use-of-prototype-vs-this-in-javascript – Felix Kling Oct 25 '12 at 01:48

0 Answers0