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 factorial(n) { | |
return n === 0 ? 1 : n <= 2 ? n : n * factorial(n - 1); | |
}; |
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 parseURL(url){ | |
var l = document.createElement("a"); | |
l.href = url; | |
// output object | |
var o = { | |
// parts of parsed URL | |
hash: l.hash, | |
host: l.host, | |
hostname: l.hostname, | |
href:l.href, |
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(){ | |
if (window.addEventListener) window.addEventListener("load", init, false); | |
else if (window.attachEvent) window.attachEvent("onload", init); | |
function init(){} | |
})(); |
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
if (!window.Node) { | |
var Node = { | |
ELEMENT_NODE: 1, | |
ATTRIBUTE_NODE: 2, | |
TEXT_NODE: 3, | |
COMMENT_NODE: 8, | |
DOCUMENT_NODE: 9, | |
DOCUMENT_FRAGMENT_NODE: 11 | |
} | |
} |
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
/** Universal function for unobtrusive adding event handler to element. | |
* It doesn't replace yet binded handler, for example in the tag. | |
* It returns value of the new handler, so values of previous handlers | |
* will be replaced. | |
* | |
* Arguments: | |
* element: target HTML element of binding, | |
* event: string with name of the event, for example, 'onclick', | |
* newHandler: function to be binded. | |
**/ |
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
// from Flanagan book | |
window.onerror = function (msg, url, line) { | |
if (onerror.num++ < onerror.max) { | |
alert("Error: " + msg + "\n" + url + ":" line); | |
return true; | |
} | |
} | |
onerror.max = 3; | |
onerror.num = 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
/** | |
Without waiting in browsers Opera and Webkit: | |
if pics are allowed | |
'img.complete' puts on 'true' only after event | |
'onload', 'onerror' or 'onabort' | |
if pics are not allowed | |
instantly 'img.complete' becomes 'true', and 'onload' doesn't occurs | |
у IE: | |
if pics are allowed | |
property 'readyState' [*] changes two times |
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 randomInt(n) { | |
return Math.round(Math.random() * n); | |
} |
OlderNewer