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
String.prototype.template = function (scopeEval) { | |
// Andrea Giammarchi - WTFPL License | |
var | |
re = /\$\{([\S\s]*?)\}/g, | |
evaluate = [], | |
i = 0, | |
m | |
; | |
while (m = re.exec(this)) { | |
evaluate.push( |
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 i,n=300000; | |
var d0=new Date().getTime(); | |
for(i=0;i<n;++i) | |
"1.5"-0; | |
alert("-0: "+(new Date().getTime()-d0)+" ms"); | |
var d0=new Date().getTime(); | |
for(i=0;i<n;++i) | |
+"1.5"; |
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
// Sorry. Hack fail :( | |
// "Speedup" in opera and chrome because bugs in webkit (compile return undefined) | |
// and opera (invalid regexp object return). | |
// Giant thanks to @jdalton and @diegoperini | |
var i,n=20000; | |
var i=0; | |
var t=""; | |
for(i=0;i<10000;++i) | |
t+=" a"; |
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 repeatStringBinary(str, how_many) | |
{ | |
how_many|=0; // convert to number and round | |
str+=""; // convert to string | |
if(how_many<=0 || str.length==0) | |
return ""; | |
if(how_many==1) | |
return str; | |
if(how_many==2) |
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 repeatString(str, how_many) | |
{ | |
how_many|=0; // convert to number and round | |
str+=""; // convert to string | |
if(how_many<=0 || str.length==0) | |
return ""; | |
if(how_many==1) | |
return str; | |
if(how_many==2) |
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
/** | |
@fn construct HTMLDocumentFragment or HTMLElement from 'html' string in 'doc' | |
@param html string that contains html | |
@param doc owner HTMLDocument for result. Optional | |
@return HTMLDocumentFragment or HTMLElement depend from 'html' | |
*/ | |
$jb.DOMNode._fromHTML=null; | |
if("applyElement" in $h) | |
{ |
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
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
/* MODIFY PROTOTYPE */ | |
var _fn=function(){}; | |
_fn.prototype.a=1; | |
var v=new _fn(); | |
alert(v.a === 1); /* true */ | |
alert(v.constructor === _fn); /* true */ | |
/* REPLACE PROTOTYPE */ |
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 i,n=3000, j; | |
var a=document.getElementsByTagName('li'), m = a.length, v; | |
for(j = 0 ; j < m ; ++j) | |
a[j].b = {}; | |
console.time("1"); | |
for(i = 0 ; i < n ; ++i) | |
for(j = 0 ; j < m ; ++j) |
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
// tnx http://4umi.com/web/javascript/optimize.php for idea, but while(i--) the best :) (except opera :/) | |
var _fn = function(){}; | |
var i, n=30, j, m = 100000; | |
console.time("1"); | |
i = n; while(i--) | |
{ | |
for( j = 0; j < m; j++ ) _fn(); | |
} |
OlderNewer