Navigation Menu

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 http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --without-ssl --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl http://npmjs.org/install.sh | sh
@matthewrobb
matthewrobb / 1.md
Created November 30, 2012 18:07 — forked from getify/1.md
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
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();
@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 / 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 / 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];
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
@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>
<script src="http://static.jsbin.com/js/vendor/traceur.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
@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