Hacker News new | ask | show | jobs
by rizalp 4237 days ago
I've using Js for quite some time, and the behavior of prototype chain and instanceof always give me headache when I'm trying to do simple inheritance...

For now, I'll keep using `_.create` to do Inheritance. Of course it means another library to keep using and more verbose. But whatever...

    var Person = function(){ User.call(this) };

    Person.prototype = _.create(User.prototype, { 'constructor': Person });

    var p = new Person();

    p instanceof User //true
    p instanceof Person //true