This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Sample IIFE + Augmentation | |
| Here I created a module counter, | |
| and augmented it (added reset function). | |
| */ | |
| var counter = (function() { | |
| var count = 0 | |
| return { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Metalsmith = require('metalsmith') | |
| , markdown = require('metalsmith-markdown') | |
| , templates = require('metalsmith-templates') | |
| , Handlebars = require('handlebars') | |
| , fs = require('fs') | |
| , collections = require('metalsmith-collections') | |
| , permalinks = require('metalsmith-permalinks') | |
| Handlebars.registerPartial('header', fs.readFileSync(__dirname + '/templates/partials/header.hbt').toString()) | |
| Handlebars.registerPartial('footer', fs.readFileSync(__dirname + '/templates/partials/footer.hbt').toString()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var classifyShape = function(shape) { | |
| var isTriangle = function() { | |
| console.log('A triangle is a polygon with 3 sides.') | |
| } | |
| var isQuadrangle = function() { | |
| console.log('A quadrangle is a polygon with 4 sides.') | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var pojo = function () { | |
| var members = arguments | |
| , ctr = 0 | |
| return function () { | |
| var obj = {} | |
| , i = 0 | |
| , len = members.length | |
| ctr += 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var myObject = { name : 'flipjs' } | |
| console.log('Start observing...') | |
| Object.observe(myObject, function(changes) { | |
| changes.forEach(function(change) { | |
| console.log(change.name | |
| + " was " | |
| + change.type | |
| + " and is now " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var trutheyTester = function(expr) { | |
| return expr ? "truthey" : "falsey"; | |
| } | |
| trutheyTester({}); //truthey (an object is always true) | |
| trutheyTester(false); //falsey | |
| trutheyTester(new Boolean(false)); //truthey (an object!) | |
| trutheyTester(""); //falsey |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var toType = function(obj) { | |
| return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase() | |
| } | |
| toType({a: 4}); //"object" | |
| toType([1, 2, 3]); //"array" | |
| (function() {console.log(toType(arguments))})(); //arguments | |
| toType(new ReferenceError); //"error" | |
| toType(new Date); //"date" | |
| toType(/a-z/); //"regexp" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function(){ | |
| var traverse = function(util, searchTerm, options) { | |
| var options = options || {}; | |
| var obj = options.obj || window; | |
| var path = options.path || ((obj==window) ? "window" : ""); | |
| var props = Object.keys(obj); | |
| props.forEach(function(prop) { | |
| if ((tests[util] || util)(searchTerm, obj, prop)){ | |
| console.log([path, ".", prop].join(""), "->",["(", typeof obj[prop], ")"].join(""), obj[prop]); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var mongo = require('mongodb') | |
| var Server = mongo.Server | |
| , Db = mongo.Db | |
| , BSON = mongo.BSONPure | |
| var server = new Server('localhost', 27017, {auto_reconnect: true}) | |
| , db = new Db('dbName', server) | |
| db.open(function(err, db) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var arr = [1, 2, 3, 4, 5, 6, 7] | |
| , results = [] | |
| , len = arr.length | |
| ;(function iterator(i) { | |
| if (i >= len) { | |
| callback(null, results) | |
| } else { | |
| async_work(function(err, res) { | |
| if (err) { |
OlderNewer