JavaScriptメモ
Object.create メソッド
p.26, 3.5 プロトタイプ
if (typeof Object.create !== 'function') { Object.create = function (o) { var F = function () {}; F.prototype = o; return new F(); } }
実行例
var A = {}; var a = Object.create(A); print(a instanceof A); // true
Function.method メソッド
p.38, 4.7 変数型の拡張
Function.prototype.method = function (name, func) { this.prototype[name] = func; return this; };
実行例
Number.method('integer', function () { return Math[this < 0 ? 'ceil' : 'floor'](this); }); print( (-10 / 3).integer() ); // -3