This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function times(n, fn) { | |
var arr = []; | |
for (var i = 0; i < n; i++) { | |
var res = fn(i); | |
if (typeof res != 'undefined') { | |
arr.push(res); | |
} | |
} | |
return arr; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ctor(fn) { | |
function F () { | |
var obj = Object.create(F.prototype); | |
fn.apply(obj, arguments); | |
return obj; | |
} | |
F.prototype = Object.create(fn.prototype); | |
return F; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getType(obj) { | |
var type = typeof obj; | |
return (type == 'object' && obj === null) ? 'null' : type; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert wildcard pattern to RegExp | |
* Pattern: | |
* * - Zero or more characters | |
* ? - Exactly one character | |
* | |
* @param {String} pattern Wildcard pattern | |
* @returns {RegExp} regular expression for wildcard matching | |
*/ | |
function wc2reg(pattern) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lib = { | |
/* | |
* PRNG - Linear congruential generator | |
* The random cycle is 2^32 | |
* @retuns {unsigned integer} Next random seed | |
*/ | |
rand : (function () { | |
var seed = new Date; | |
return function () { | |
seed = (seed * 69069 + 1) >>> 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var GO = 'GO', | |
OK = 'OK', | |
SIGN = 'SIGN', | |
LZERO = 'LZERO', | |
INT = 'INT', | |
FRAC = 'FRAC', | |
FDIG = 'FDIG', | |
EXP = 'EXP', | |
XSIGN = 'XSIGN', | |
EDIG = 'EDIG', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.factory = function () { | |
var cnt = this; | |
return function () { | |
var obj = Object.create(cnt.prototype); | |
cnt.apply(obj, arguments); | |
return obj; | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var PROTO_TYPE = { | |
'[object String]' : String, | |
'[object Number]' : Number, | |
'[object Boolean]' : Boolean | |
}; | |
function applyNew(f, a) { | |
var construct = PROTO_TYPE[{}.toString.call(f.prototype)]; | |
if (construct) { | |
return new construct(a[0]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function StatNode() { | |
this.dns = 0; | |
this.connect = 0; | |
this.first = 0; | |
this.last = 0; | |
} | |
StatNode.prototype.setParam = function (param, value) { | |
//... | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getId () { | |
return getId.id++; | |
} | |
getId.id = 0; | |
function Foo() { | |
this.__id__ = getId(); | |
} | |
Foo.prototype.valueOf = function () { |