Skip to content Skip to sidebar Skip to footer

Js Run Function From Constructor After Object Instantiation

Is it possible to do this: var hammer = new Hammer(); // create a new instance hammer(nail); // really call Hammer.prototoype.hit(object); I can figure it out on a raw object, but

Solution 1:

One solution is to not create a constructor function at all:

var hammer = newHammer();

hammer(nail);

hammer.clean();

functionnewHammer(options) {
    var config = options.blah;

    hit.clean = clean;

    return hit;

    functionhit(obj) {
        // ...
    }

    functionclean() {
        // ...
    }
}

To me, this is a much cleaner solution than messing around with constructors and prototypes.

Post a Comment for "Js Run Function From Constructor After Object Instantiation"