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 wtf(x) { | |
var f = | |
function(x) | |
{ | |
alert(x); | |
} | |
var function = alert; | |
} |
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
// *** Step 1a: method.call; must assume F.p.call not mutated | |
// app code: | |
var method = other.method; | |
method.call(self, arg0, arg1, ...); | |
// *** Step 1b: save .call up front; but still uses .call again! | |
// library code: | |
var callMethod = Function.prototype.call; | |
// app code: | |
var method = other.method; |
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 sax = require("sax"); | |
var fs = require("fs"); | |
function getCdata(path, cb) { | |
var results = []; | |
var stream = fs.createReadStream(path); | |
var saxStream = sax.createStream(false, { lowercasetags: true }); | |
var cdata; | |
saxStream.on("opencdata", function() { | |
console.log("OPEN CDATA"); |
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
// Demonstrating @jashkenas's examples in an even-more-minimalist version of | |
// classes that only allow object-literal syntax for the class body. | |
// Basic usage; unchanged. | |
class Color { | |
constructor: function(hex) { | |
... | |
}, |
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
// Examples using something closer to my original "minimal classes" proposal. | |
// There are several benefits to this approach. | |
// First, it uses a familiar approach to separating prototype properties from | |
// instance properties: methods are on the prototype, and static declarations | |
// are prototype data properties. Otherwise, instance properties are only | |
// declared in the constructor body. | |
// Second, instead of object literal syntax, it uses a property declaration |
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
Array.from = function from(x) { | |
var result = new Array(); | |
for (var i = 0, n = x.length; i < n; i++) { | |
if (i in x) | |
result[i] = x[i]; | |
} | |
return result; | |
}; | |
// If Object.getPrototypeOf(Subarray) === Array, then: |
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
// inspired by https://github.com/raganwald/homoiconic/blob/master/2011/11/sans-titre.md#readme | |
// traditional method chaining with combinators: | |
console.log(range(1, 3) | |
.concat(range(4, 6)) | |
.map(function(x) { return x * x }) | |
.filter(function(x) { return x % 2 === 0 }) | |
.reverse()); | |
// method chaining with cascades: |
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
// inspired by https://github.com/raganwald/homoiconic/blob/master/2011/11/sans-titre.md#readme | |
// and by https://groups.google.com/a/dartlang.org/group/misc/browse_thread/thread/611c04100ac17142 | |
// traditional method chaining with combinators: | |
console.log(range(1, 3) | |
.concat(range(4, 6)) | |
.map(function(x) { return x * x }) | |
.filter(function(x) { return x % 2 === 0 }) | |
.reverse()); |
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
// inspired by https://github.com/raganwald/homoiconic/blob/master/2011/11/sans-titre.md#readme | |
// and by https://groups.google.com/a/dartlang.org/group/misc/browse_thread/thread/611c04100ac17142 | |
// traditional method chaining with combinators: | |
console.log(range(1, 3) | |
.concat(range(4, 6)) | |
.map(function(x) { return x * x }) | |
.filter(function(x) { return x % 2 === 0 }) | |
.reverse()); |
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
// inspired by https://github.com/raganwald/homoiconic/blob/master/2011/11/sans-titre.md#readme | |
// and by https://groups.google.com/a/dartlang.org/group/misc/browse_thread/thread/611c04100ac17142 | |
// traditional method chaining with combinators: | |
console.log(range(1, 3) | |
.concat(range(4, 6)) | |
.map(function(x) { return x * x }) | |
.filter(function(x) { return x % 2 === 0 }) | |
.reverse()); |
OlderNewer