Mercurial > laserkard
view good-parts/first.js @ 101:2bec541ef58f laserkard
made it HTML 4.1 strict
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 27 Jul 2010 08:39:43 -0400 |
parents | 343dc947f999 |
children |
line wrap: on
line source
1 document.writeln("hello world!");3 Function.prototype.method = function (name, func) {4 this.prototype[name] = func;5 return this;6 };9 if (typeof Object.create !== 'function') {10 Object.create = function (o) {11 var F = function () {};12 F.prototype = o;13 return new F();14 };}16 Number.method('integer', function ( ) {17 return Math[this < 0 ? 'ceil' : 'floor'](this);18 });20 String.method('trim', function ( ) {21 return this.replace(/^\s+|\s+$/g, '');22 });25 document.writeln((-10 / 3).integer( ));27 document.writeln("whatev ".trim());28 document.writeln("whatev ");30 Function.method('curry', function ( ) {31 var slice = Array.prototype.slice,32 args = slice.apply(arguments),33 that = this;34 return function ( ) {35 return that.apply(null, args.concat(slice.apply(arguments)));36 };37 });39 var memoizer = function (memo, formula) {40 var recur = function (n) {41 var result = memo[n];42 if (typeof result !== 'number') {43 result = formula(recur, n);44 memo[n] = result;45 }46 return result;47 };48 return recur;49 };