Skip to content

Instantly share code, notes, and snippets.

<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
<div id="the_div">
<ul id="the_list">
<li id="the_item">Click me!</li>
</ul>
function convertToArray(iterable) {
return Array.prototype.slice.call(arguments);
}
Function.prototype.curry = function(){
if (!arguments.length) return this;
var __method = this, args = convertToArray(arguments);
return function() {
return __method.apply(this, args.concat(convertToArray(arguments)));
}
}
var cachy = (function() {
var cache = {}
var executor = function(func, args) {
var funcIdentifier = func.toString(),
argsIdentifier = args.join(", ")
if(cache.hasOwnProperty(funcIdentifier) && cache[func.toString()].hasOwnProperty(argsIdentifier)) {
console.log("cached baby!")
return cache[funcIdentifier][argsIdentifier]
} else {
// 1. Write a class to support the following code:
var Person = function(name){ this.name = name }
var instanceMethods = {
getName: function(){
return this.name
}
}
for(var name in instanceMethods) {
Person.prototype[name] = instanceMethods[name]
}
+new Date
// 1. Write a class to support the following code:
var Person = function(name){ this.name = name }
Person.prototype.getName = function(){
return this.name
}
var thomas = new Person('Thomas');
var amy = new Person('Amy');
console.log(thomas.name) // --> "Thomas"
@sdepold
sdepold / JSMasterclass - Ex8
Created October 19, 2010 19:21
Meep meep
// 1. Write a class to support the following code:
var Person = function(name){ this.name = name }
Person.prototype = {
getName: function(){
return this.name
}
}
var thomas = new Person('Thomas');
var amy = new Person('Amy');
@sdepold
sdepold / Closure 2
Created October 19, 2010 18:25
Closure 1
// Exercise 2 - Closures
// Wrap the following code in a closure and export only the "countdown" function.
// Code
(function(name, obj) {
var index;
function log(){
console.log(index);
@sdepold
sdepold / JSMasterclass
Created October 19, 2010 18:20
Closures
// Exercise 2 - Closures
// Wrap the following code in a closure and export only the "countdown" function.
// Code
(function(name, obj) {
var index;
function log(){
console.log(index);
var tags = tags_text.split(',');
var errors = [];
if (errors.length > 0) {
} else {
var new_question = new db.Question({
title: title,
body: body,
doNotify: doNotify,