rlm@79: document.writeln("hello world!"); rlm@79: rlm@79: Function.prototype.method = function (name, func) { rlm@79: this.prototype[name] = func; rlm@79: return this; rlm@79: }; rlm@79: rlm@79: rlm@79: if (typeof Object.create !== 'function') { rlm@79: Object.create = function (o) { rlm@79: var F = function () {}; rlm@79: F.prototype = o; rlm@79: return new F(); rlm@79: };} rlm@79: rlm@79: Number.method('integer', function ( ) { rlm@79: return Math[this < 0 ? 'ceil' : 'floor'](this); rlm@79: }); rlm@79: rlm@79: String.method('trim', function ( ) { rlm@79: return this.replace(/^\s+|\s+$/g, ''); rlm@79: }); rlm@79: rlm@79: rlm@79: document.writeln((-10 / 3).integer( )); rlm@79: rlm@79: document.writeln("whatev ".trim()); rlm@79: document.writeln("whatev "); rlm@79: rlm@79: Function.method('curry', function ( ) { rlm@79: var slice = Array.prototype.slice, rlm@79: args = slice.apply(arguments), rlm@79: that = this; rlm@79: return function ( ) { rlm@79: return that.apply(null, args.concat(slice.apply(arguments))); rlm@79: }; rlm@79: }); rlm@79: rlm@79: var memoizer = function (memo, formula) { rlm@79: var recur = function (n) { rlm@79: var result = memo[n]; rlm@79: if (typeof result !== 'number') { rlm@79: result = formula(recur, n); rlm@79: memo[n] = result; rlm@79: } rlm@79: return result; rlm@79: }; rlm@79: return recur; rlm@79: };