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
/* can you spot what is happening here */ | |
/* the alert("X") should never execute */ | |
<script> | |
onload = function() { | |
var fn = function() { | |
alert("X"); | |
} | |
(function() { })(); |
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
/* | |
Checks that `toString` of constructor's prototype has "special" behavior (i.e. is `Object.prototype.toString`) as per 15.2.4.2 | |
Cons: | |
- Relies on `constructor` property of an object (as well as `toString` of constructor's prototype) being present and not augmented | |
(will fail on host objects in IE that lack constructor, but could be guarded against) | |
- Does not differentiate between Object objects created implicitly via function constructor and those created explicitly via Object | |
Pros: |
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
/** | |
* Example: | |
* 'hello {{username}}'.between('{{','}}') === 'username' | |
*/ | |
String.prototype.between_regexp = function between(begin, end) { | |
var regexp = new RegExp(begin + '(.+)' + end); | |
return this.match(regexp)[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
<script> | |
/* Alternate snippet to asynchronously embed the Google Analytics script. | |
* This requires the following things of the pages that will contain it: | |
* 1. the page only include one GA tracker (common case), | |
* 2. the page is not be behind SSL (http, not https), | |
* 3. this script block can be in the <head> or <body> elements | |
*/ | |
var _gaq = [['_setAccount', 'UA-XXXXXX-X'],['_trackPageview']]; | |
(function(d) { |
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
/** | |
* Aliases and additional "sugar" | |
* 2010-04-15 | |
* @author Dmitry A. Soshnikov | |
*/ | |
(function () { | |
["defineProperty", "defineProperties", "keys", "getOwnPropertyNames", | |
"getOwnPropertyDescriptor", "getPrototypeOf", "seal", "freeze", | |
"preventExtensions", "isFrozen", "isSealed", "isExtensible"] |
// @kangax fix yur SubArray (ES5 flavor) kthxbai
// http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/#ecmascript_5_accessors_to_the_rescue
// (C) Juriy Zaytsev (aka @kangax) - MIT Style License
// http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/
var SubArray = (function() {
var MAX_SIGNED_INT_VALUE = Math.pow(2, 32) - 1,
hasOwnProperty = {}.hasOwnProperty,
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 query = (function() { | |
var query, engine, engines = ('NW.Dom.select,base2.dom.querySelectorAll,Sizzle,$$,$,jQuery,'+ | |
'YAHOO.util.Selector.query,dojo.query,Ext.DomQuery.select,document.querySelectorAll').split(','); | |
while (engine = engines.shift()) { | |
if (Function('try{ var els = ' + engine + '("*"); return els.length > 0 }catch(e){}')()) { | |
query = Function('cssExpr', 'return ' + engine + '(' + | |
(/^base2/.test(engine) ? 'document,' : '') + 'cssExpr)'); | |
break; | |
} |
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
/** | |
* Provides requestAnimationFrame in a cross browser way. | |
* @author greggman / http://greggman.com/ | |
*/ | |
if (!window.requestAnimationFrame) { | |
window.requestAnimationFrame = | |
window.webkitRequestAnimationFrame || | |
window.mozRequestAnimationFrame || | |
window.oRequestAnimationFrame || |
OlderNewer