Skip to content

Instantly share code, notes, and snippets.

@makenova
makenova / index.js
Created August 31, 2015 16:54
messing with this and node module.exports
pt = require('./thisy');
pt.printthis();
@makenova
makenova / module.js
Created July 1, 2015 21:35
JS module pattern
function evilCorp (name, laugh){
this.name = name;
this.laugh = laugh;
}
evilCorp.prototype.takeover = function(){
return "My name is " + this.name + " and I am your new master! " + this.laugh;
}
var $ = new evilCorp('condescendingSeniorDev', 'muwahaha');
{"answers":["function(console) {\n\tvar names = [\"Ben\", \"Jafar\", \"Matt\", \"Priya\", \"Brian\"],\n\t\tcounter;\n\n\tfor(counter = 0; counter < names.length; counter++) {\n\t\tconsole.log(names[counter]);\n\t}\n}\n\t\t","function(console) {\n\tvar names = [\"Ben\", \"Jafar\", \"Matt\", \"Priya\", \"Brian\"];\n\n\tnames.forEach(function(name) {\n\t\tconsole.log(name);\n\t});\n}\n\t\t","function() {\n\tvar newReleases = [\n\t\t{\n\t\t\t\"id\": 70111470,\n\t\t\t\"title\": \"Die Hard\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/DieHard.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": [4.0],\n\t\t\t\"bookmark\": []\n\t\t},\n\t\t{\n\t\t\t\"id\": 654356453,\n\t\t\t\"title\": \"Bad Boys\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/BadBoys.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": [5.0],\n\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t},\n\...he largest rating. Rem

Keybase proof

I hereby claim:

  • I am makenova on github.
  • I am makenova (https://keybase.io/makenova) on keybase.
  • I have a public key whose fingerprint is ABA1 B0AE B622 C620 22A6 3014 60B0 E968 3FF9 37AA

To claim this, I am signing this object:

@makenova
makenova / okdemo.md
Created July 30, 2014 23:58
OKCoders talk about tooling and the dev experience
@makenova
makenova / constructor_vs_prototype.md
Created May 9, 2014 00:00
Notes on the JavaScript prototype chain

Adding methods on the Constructor vs the prototype

Adding a method on the constructor will duplicate that method for every instance of the object that created, consuming memory but also granting the method access private variables on the object. Adding a method on the prototype will will not duplicate it for new instances, conserving memory while leaving it available to all instances.

// Constructor with greet method directly on it.
var Person = function (name, age) {
@makenova
makenova / javascript-under-pressure.md
Created April 27, 2014 06:33
javascript under pressure solutions

These are my solutis that I came up with while doing the JS Challenge at usvsth3m. They were reached 'under pressure' as the title implies, hence there are no optimizations and it looks rough.
The problem description is stated before the solution.

Code as fast as you can! You need to double the integer and return it. To test your code, click Go or hit Ctrl-Enter/⌘-Enter.

function doubleInteger(i) {
@makenova
makenova / Question.md
Last active August 29, 2015 13:59
JS callback async confusion

What makes a JS function async?

Is it possible to write a custom asynchronous function without the use of JS's timer functions such as setTimeout and setInterval ?

I have two code examples below, one that succeeds(goodboy.js) and one that fails(goodboyfail.js). I originally thought, goodboy.js would fail because I assumed

  1. Simply defining get with a callback function would make it asyncronous
  2. praise would be undefined when it was executed.

However, the console.log messages seem to indicate that the get function executes syncronously. I got the expected behviour in goodboyfail.js by adding a delay.

@makenova
makenova / jsScope.md
Created April 15, 2014 20:44
Notes from JSconf video on JS scope

A Little This, a Little _that: Understanding Scope in JavaScript

These are notes I made while watching this video by David Aragon from jQuery conf 2014. He was kind enough to share his slides here.
I have copied some of his examples form the slides to provide context for my notes, some of them have been slightly modified. Any errors, are likely my own. Caveat Lector.

Scope

JS uses functional scope not block scope like C or Scala, e.g. the if(){} 'block' is not its own scope

This is the test

The quck brown fox jumped over the lazy dog.

This is a sub heading

This is a second test paragraph. I am writing words that will appear on a page.