Skip to content

Instantly share code, notes, and snippets.

echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl | tar xz --strip-components=1
./configure --without-ssl --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl | sh
matthewrobb /
Created November 30, 2012 18:07 — forked from getify/
rethink how javascript "inheritance" ACTUALLY works...

JavaScript does not have "inheritance" or "prototypal inheritance" or "classes" or any of that jazz... what you've been told, and how you've been taught about it, are a misunderstanding... all this nonsense about constructor functions and new and such... that's all hogwash... well, it's all unnecessary effort, at best.

"Instead... only try to realize the truth... there is no spoon."

What JavaScript does have is "behavior delegation"... and object linking through the "prototype chain"... you merely link two instances of objects together, say Foo and Baz, and say that Baz "delegates" to Foo for any behavior that Baz doesn't own itself but that Foo does own. And thus, any object b (aka, "b is an instance of Baz" in the more confusing terminology) which is linked to Baz, delegates first to Baz, and then to Foo, for behavior.

That's it. Seriously. And function constructors and new and all that stuff, everything you've read before about OO in JS, they're just distractions that lea

matthewrobb / robot.js
Created December 4, 2012 22:39
function Robot(robot) {
Robot.prototype = {
constructor: Robot,
bots: [],
onIdle: function(ev) {
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 / bindAsync.js
Last active December 17, 2015 22:09
Async function bind.
var bindAsync = function(fn, ctx) {
return function() {
setTimeout(, fn, ctx || this, arguments), 0);
matthewrobb / inheritize.js
Last active December 27, 2015 00:39
Recursive object descent and prototype reassignment
function inheritize(root){
var branch = root[key];
if (typeof branch === "object") {
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];
<!DOCTYPE html>
<meta charset="utf-8">
<title>JS Bin</title>
matthewrobb / strict.with.js
Last active August 29, 2015 14:01
Strict function inside with statement ?
(function() {
with(this) {
(function() {
"use strict";
foo = "boo";
<!DOCTYPE html>
<script src=""></script>
<meta charset="utf-8">
<title>JS Bin</title>
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