Skip to content

Instantly share code, notes, and snippets.

export var counter = 0;
function inc_a(cb){
console.log(counter++);
if(counter < 100) {
setTimeout(inc_a, 0, [ cb ]);
} else {
cb();
}
}
import { odd as local_odd } from "./b";
export var counter = 0;
export default function even(n) {
console.log("even has run %s times", counter++);
return n === 0 || local_odd(n - 1);
}
@matthewrobb
matthewrobb / input.es6.js
Last active August 29, 2015 14:02
Proposal for a more performant es5 target for es6 module transpilers
import { readFile, readDir } from "fs";
export function mkdir() {
// do stuff with readFile & readDir
}
export var count;
for(count = 0; count < 100;) {
console.log(count++); // 0...99
<!DOCTYPE html>
<html>
<head>
<script src="http://static.jsbin.com/js/vendor/traceur.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
@matthewrobb
matthewrobb / strict.with.js
Last active August 29, 2015 14:01
Strict function inside with statement ?
(function() {
with(this) {
(function() {
"use strict";
foo = "boo";
console.log(this.foo);
}).call(this);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
@matthewrobb
matthewrobb / inheritize.js
Last active December 27, 2015 00:39
Recursive object descent and prototype reassignment
function inheritize(root){
Object.keys(root).forEach(function(key){
var branch = root[key];
if (typeof branch === "object") {
Object.keys(branch).forEach(function(key){
var leaf = branch[key];
if (typeof leaf === "object" && typeof root[key] === "object") {
// In the HOPEFULLY near future this would be replaced with:
// Object.setPrototypeOf(leaf, root[key]);
leaf.__proto__ = root[key];
@matthewrobb
matthewrobb / bindAsync.js
Last active December 17, 2015 22:09
Async function bind.
var bindAsync = function(fn, ctx) {
return function() {
setTimeout(fn.bind.call(fn.apply, fn, ctx || this, arguments), 0);
}
};
@matthewrobb
matthewrobb / gist:5272889
Created March 29, 2013 19:06
Simple mixin function with prototype support
function mixin(receiver, source) {
var descriptors = {};
for(var name in source) {
if(source.hasOwnProperty(name)) {
if(typeof receiver == "function" && name == "prototype") {
receiver.prototype = mixin(Object.create(receiver.prototype), source.prototype);
} else {
descriptors[name] = Object.getOwnPropertyDescriptor(source, name);
}
}
@matthewrobb
matthewrobb / robot.js
Created December 4, 2012 22:39
Phenbot
function Robot(robot) {
this.bots.push(this);
};
Robot.prototype = {
constructor: Robot,
bots: [],
onIdle: function(ev) {
ev.robot.clone();