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
Object.getPropertyNames || | |
Object.defineProperty(Object, "getPropertyNames", { | |
value: function(obj) { | |
var propertyNames = []; | |
do { | |
propertyNames.push.apply(propertyNames, Object.getOwnPropertyNames(obj)); | |
obj = Object.getPrototypeOf(obj); | |
} while (obj); | |
// get unique property names | |
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
// WebKit strict mode bugs | |
// Eval code should be "strict eval code" if the call to eval is a direct call (15.1.2.1.1) to | |
// the eval function that is contained in strict mode code: | |
(function () { | |
"use strict"; | |
return eval('(function() { return !this; })()'); | |
})(); | |
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 (typeof Array.isArray != 'function') { | |
Array.isArray = (function () { | |
var toString = Object.prototype.toString; | |
return function (obj) { | |
return toString.call(obj) == '[object Array]'; | |
}; | |
})(); | |
} |
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 library defines a new style ES objects | |
* which support delegation based mixins. A mixin | |
* chain is stored in the internal [[Mixin]] property. | |
* | |
* Used features: Harmony (ES6) proxies. | |
* | |
* Tested in FF4 beta. | |
* | |
* @author Dmitry A. Soshnikov <[email protected]> |
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 obj = { foo: function () { return "bar"; } }; | |
var jsonString = JSON.stringify(obj, function (key, value) { | |
if (typeof value == 'function') { | |
return value(); | |
} | |
return value; | |
}); | |
// Firefox <= 3.6, produces invalid JSON: '{"foo":}' |
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
/** | |
* Written by Asen Bozhilov | |
* http://code.google.com/p/js-examples/source/browse/trunk/JSON.js | |
*/ | |
if (!this.JSON) { | |
this.JSON = { | |
parse : (function (undefined) { | |
var JSON_GRAMMAR = { | |
STRING : '"([^"\\x00-\\x1F\\\\]|\\\\["\\\\\/bfnrt]|\\\\u[0-9A-Fa-f]{4})*"', |
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
/** | |
* BESEN bug on String index named properties | |
* | |
* There are some problems accessing the named properties of String | |
* objects that correspond to the individual characters of its | |
* [[PrimitiveValue]]. | |
* | |
* Tested on BESEN r117 | |
*/ |
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
// BESEN wrong behavior of the logical && and || operators | |
// Tested on r111 | |
var obj = {}; | |
// Logical AND operator | |
print(obj && obj); // prints true, expected '[object Object]' | |
print(obj && 'foo'); // prints '[object Object]', expected 'foo' | |
print(obj && 4); // prints '[object Object]', expected 4 | |
print(obj && NaN); // prints false, expected NaN |
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
// Generic function to subclass an array in JavaScript | |
// (using the ECMAScript Harmony Proxy features) | |
// Structuring of code inspired by @kangax's | |
// array_subclassing (http://github.com/kangax/array_subclassing) | |
var makeSubArray = (function () { | |
var MAX_UINT32 = Math.pow(2, 32) - 1; | |
return function (properties) { | |
properties || (properties = {}); |
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
// newApply: Invoke a consturctor function correctly, passing an arbitrary | |
// number of arguments | |
function newApply(fn, argsArray) { // (c) Christian C. Salvadó - MIT License | |
var F = newApply, obj, ret, t, isPrimitive; | |
if (this instanceof F) return; // this function is used as a dummy constructor | |
F.prototype = fn.prototype; // set up the prototype and constructor properties | |
F.prototype.constructor = fn; |