Joined December 2012
·

Avétis KAZARIAN

Paris, FRANCE
·
·

@siyad: well this (my version and your comment) is all obsolete. Now we have nice ES 6 Class :)

Ha Ha Ha ! :-)

Actually, one thing I learnt from JS is that good practice comes from...practice.

And lots of code analysis.

Compare this:

var ParentClass = function () {
  this.x = 3;
};
var ChildClass = function () {};

// new
ChildClass.prototype = new ParentClass();

var instance1 = new ChildClass();
console.log(instance1.x); // => 3

// Object.create()
ChildClass.prototype = Object.create(ParentClass);

var instance2 = new ChildClass();
console.log(instance2.x) // => undefined

Object.create() won't call the constructor, which is obviously better as you can't pass arguments to ParentChild when defining ChildClass prototype:

var ParentChild = function (mandatoryArg) {
  if (! mandatoryArg) {
    throw new Error('Missing argument.');
  }

  doStuff(mandatoryArg);
};

var ChildClass = function () {};

ChildClass.prototype = new ParentChild(); // will break

I strongly recommend you to read this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create

Actually, that's a very bad idea.

For instance, on your website (http://theagilemonkeys.com/) if someone wants to change the font size (native zooming), they'll come to the very disappointing evidence that it is impossible.

Such minimal accessibility features of the browser should always be kept as they are.

Achievements
83 Karma
10,540 Total ProTip Views
Interests & Skills