News for hackers. Stuff that matters.
Re:OO JS in 15mins or Less by president on Monday April 30, 2012 @11:22AM (#3909615)
"Constructor notation is preferred when you need to set initial properties and methods on an object or you plan on creating multiple instances of an object where the properties and methods of each instance need to be unique."

Love it when they don't just tell you how to do something. Would like to see more people write on when you should use something.

Re:OO JS in 15mins or Less by recursive on Monday April 30, 2012 @11:48AM (#3909712)
> Love it when they don't just tell you how to do something.

Or why. None of the examples seem like constructors provide any advantage over literals.

Re:OO JS in 15mins or Less by ww520 on Monday April 30, 2012 @12:33PM (#3909944)
So that the methods don't need to be re-defined for every object.
Re:OO JS in 15mins or Less by recursive on Monday April 30, 2012 @01:57PM (#3910422)
Object literals don't require you to duplicate any code:

    function getObject(val1, val2) {
        return {
            foo: val1,
            bar: function() {
                return val2;
            }
        };
    }
Re:OO JS in 15mins or Less by stephenr on Tuesday May 01, 2012 @02:29AM (#3913280)
In this instance the "bar" method is redefined every time you call getObject.