JavaScript doesn't even have real OOP style classes, you just can mimic something like that.
In your example, you can achieve inheritance by doing
var Pawn = function(teamColor, pos) { Piece.call(this, teamColor, pos); }
However, you should usually attach methods to the function prototype, and not to any newly created object. In this case, you can simulate inheritance by setting up a prototype chain, for example, as CoffeeScript does:
var a, b, _ref, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; a = (function() { function a() {} return a; })(); b = (function(_super) { __extends(b, _super); function b() { _ref = b.__super__.constructor.apply(this, arguments); return _ref; } return b; })(a);
source share