Skip to content

Instantly share code, notes, and snippets.

var topics = ['Easy Handlebars Templating'];
topics.shift();
//'Easy Handlebars Templating'
@jtenner
jtenner / topics.js
Last active December 27, 2015 12:09
var topics = ['Native Loops','Functional Loops','Indications for Native Loops'];
topics.shift();
//'Native Loops'
var array = [1,2,3,4,5,6,7,8,9,10];
for(var i = 0, _len = array.length; i < _len; i++){
//do something with array[i]
}
// new snippet
var j = 0, _len = array.length;
while(j < _len){
//do something with array[j]
topics.shift();
//'Functional Loops'
var array = [1,2,3,4,5,6,7,8,9,0], target = [];
array.forEach(function(item){
//do something with each `item` here
target.push(item);
});
var closuredObjects = [/*put a bunch of objects that need a closure here*/];
closuredObjects.forEach(function(item){
var invisibleProperties = {};
item.get = function(key){
return invisibleProperties[key];
};
item.set = function(key, value){
invisibleProperties[key] = value;
return value;
topics.shift();
//'Indications for Native Loops'
function multiplyByTwo(item){return item*2;}
function addTwo(item){return item+2;}
function applyTransform(){
return Array.prototype.map.call(arguments, addTwo)
.map(multiplyByTwo)
.map(addTwo);
}
@jtenner
jtenner / gist:7346135
Created November 6, 2013 23:30
jWebAudio plugin
~function(NovelScript){
NovelScript.plugins.push(function(self){
var engine = new jWebAudio.SoundEngine();
var sources = [];
self.on('audio:add', function(audioOptions){
var source;
source = engine.addSoundSource({
'url': audioOptions.src,
'preload': true,
!function(NovelScript){
NovelScript.plugin(function(self, options){
//do something to the current NovelScript object using the options provided
});
//NovelScript.prototype is accessable here
}(NovelScript);