- An Enumerable of Rubyists @raganwald
- An Indentation of Pythonistas @raganwald
- A fold of Haskellers! @ReinH
- A Din of Twitterers @raganwald
- A callback of JavaScripters @irvingreid
- An NCC-1701 of Java Programmers @raganwald
- A relation of SQLers @raganwald
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
define("expose", [], function(){ | |
function toType(obj){ | |
return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase() | |
} | |
return function(){ | |
var list = arguments; | |
var func = /^function\s+([^(]+)/i; | |
var i=0; | |
var 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
/* | |
Demo showing how to use the usefulOrientation function. | |
*/ | |
function onDeviceOrientationChange(e){ | |
console.log("deviceOrientation", e.alpha, e.beta, e.gamma); | |
var orientation = usefulOrientation(e.alpha, e.beta, e.gamma); | |
console.log("usefulOrientatino", orientation.alpha, orientation.beta, orientation.gamma); | |
} | |
window.addEventListener("deviceorientation", onDeviceOrientationChange, false); |
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 a = 5; | |
function whatIsA() { | |
if(a == undefined) { | |
var a = 7; | |
} | |
return a; | |
} | |
whatIsA()//is it 5 or 7? |
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 is how 3 dependencies are defined using AMD. | |
Notice how when the number of dependencies grows the | |
distance between the path to the dependency and the | |
variable it is stored in grows. It quickly becomes | |
difficult to see which variable corresponds to which | |
module name. | |
*/ | |
define(["jQuery", "an/other/module", "knockout"], function($, dep, ko){ |
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
define([], function() { | |
return function deadWeight() { | |
var weight = 1000000; | |
var theWeight = new Array(weight); | |
for (var i = 0; i < weight; i++) | |
theWeight[i] = i; | |
this.getWeight = function() { return theWeight;} | |
} | |
}); |
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 component1 = { | |
//this method will receive the event and process it | |
handleEvent: function(event){ | |
//this is only for debugging | |
console.log("debugging!", event.data); | |
//the event causes the state of the component to change |
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
module _ from "underscore"; | |
import _ from "underscore"; | |
import module _ from "underscore"; | |
import {each, map, find} from "underscore"; | |
import "underscore"; | |
import default _ from "underscore"; | |
const _ = System.import("underscore"); | |
import "underscore" as _; | |
import {_} from "underscore"; | |
import {each as forEach} from "underscore"; |
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
//The file foobar.js contains these two lines of code | |
var foo = "foo", bar = "bar"; | |
export default = {foo, bar}; | |
//It can now be imported into another module using either of these two lines: | |
import foobar from "foobar"; | |
module foobar from "foobar"; | |
//But not this line: | |
import {foo, bar} from "foobar"; |
Currently you can export things from a module in at least six different ways, and import things in at least six different ways, resulting in 36 different combinations, most of which are not semantically valid.
Here is a greatly simplified (and probably naive) suggestion for modules in ES6:
###export You can only export named things, including variables and functions.
let a = "hello";
export a;
OlderNewer