Refer to .
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
jsandbox | |
.eval({ | |
code : "x=1;Math.round(Math.pow(input, ++x))", | |
input : 36.565010597564445, | |
callback: function(n) { | |
console.log("number: ", n); // number: 1337 | |
} | |
}).eval({ | |
code : "][];.]\\ (*# ($(! ~", | |
onerror: function(ex) { |
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 foo = <></>; // XMLList literal | |
foo.push(<n>0</n>, 1, 5, 3, 2, 6, 4); | |
foo.toXMLString() === "<n>0</n><n>1</n><n>5</n><n>3</n><n>2</n><n>6</n><n>4</n>"; | |
foo.sort(function(a, b) { | |
return a - b; | |
}).toXMLString() === "<n>0</n><n>1</n><n>2</n><n>3</n><n>4</n><n>5</n><n>6</n>"; | |
foo.filter(function(x) { // filter out integers less then 3 | |
if (!(x < 3)) | |
return true; | |
}).toXMLString() === "<n>3</n><n>4</n><n>5</n><n>6</n>"; |
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 results = [], | |
code = 'new Person("Elijah", "Grey")'; | |
function Person(firstname, lastname) { | |
this.name = { | |
first: firstname, | |
last: lastname | |
}; | |
} | |
results.push(code + " == " + eval(code)); |
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 getClass(obj, useNative) { | |
return Object.prototype.toString.call(obj, useNative) | |
.match(/^\[object\s(.*)\]$/)[1]; | |
} | |
function Foo(){}; // new foo == "[object Foo]" | |
var Bar = function(){}; // new Bar == "[object Object]" | |
Bar.name = "Foo"; // toStringX doesn't rely on function.name so this won't matter | |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<!-- Online here: http://code.eligrey.com/testcases/all/isObjectLiteral.html --> | |
<title>isObjectLiteral</title> | |
<style type="text/css"> | |
li { background: green; } li.FAIL { background: red; } | |
iframe { display: none; } | |
</style> |
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 (!Object.getPrototypeOf) { | |
if (typeof this.__proto__ === "object") | |
Object.getPrototypeOf = function (obj) { | |
return obj.__proto__; | |
}; | |
else { | |
Object.getPrototypeOf = function (obj) { | |
var constructor = obj.constructor, | |
oldConstructor; | |
if (Object.prototype.hasOwnProperty.call(obj, "constructor")) { |
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
XML.prototype.function::send = function (uri, callback) { | |
var prettyPrinting = XML.prettyPrinting, | |
req = new XMLHttpRequest(); | |
req.open("POST", uri, false); | |
req.setRequestHeader("Content-Type", "application/xml"); | |
if (typeof callback === "function") { | |
req.onreadystatechange = function () { | |
this.readyState === 4 && callback(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
(function () { | |
function mySolution ({ | |
var, | |
this, | |
function, | |
if, | |
return, | |
true | |
}) { | |
// prohbit reference to arguments and the test object |
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 example script uses a user-submitted script to modify image | |
// data from a canvas in which the user drew art | |
var sandbox = new JSandbox(), | |
userArt = document.getElementById("userArt").getContext("2d"), | |
imageData = userArt.getImageData(0, 0, userArt.width, userArt.height); | |
sandbox.load("user-submitted-script.js", function () { // onload | |
this.eval("doStuffWithImageData(input)", function (modifiedImageData) { | |
userArt.putImageData(modifiedImageData, 0, 0); |
OlderNewer