Skip to content

Instantly share code, notes, and snippets.

@hackjoy
Created July 2, 2015 23:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hackjoy/02e558ffe7a638a48c22 to your computer and use it in GitHub Desktop.
Save hackjoy/02e558ffe7a638a48c22 to your computer and use it in GitHub Desktop.
// Interpolate variable bindings
var name = "Bob", time = "today";
`Hello ${name}, how are you ${time}?`
// Arrows
// e => {}
// function(e){}
// Expression bodies
var odds = evens.map(v => v + 1);
var nums = evens.map((v, i) => v + i);
// Statement bodies
nums.forEach(v => {
if (v % 5 === 0)
fives.push(v);
});
// Lexical this, uses outer scope
var bob = {
_name: "Bob",
_friends: [],
printFriends() {
this._friends.forEach(f =>
console.log(this._name + " knows " + f));
}
}
// Classes
class SkinnedMesh extends THREE.Mesh {
constructor(geometry, materials) {
super(geometry, materials);
this.idMatrix = SkinnedMesh.defaultMatrix();
this.bones = [];
this.boneMatrices = [];
}
update(camera) {
super.update();
}
static defaultMatrix() {
return new THREE.Matrix4();
}
}
// Let is the new var, const is single assignment
function f() {
{
let x;
{
// okay, block scoped name
const x = "sneaky";
// error, const
x = "foo";
}
// error, already declared in block
let x = "inner";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment