Skip to content

Instantly share code, notes, and snippets.

"hello".missing; // log undefined
[][99]; // log undefined
{} + {}; // log NaN
[] + []; // log "" (empty string)
[] + {}; // log "[object Object]"
{} + []; // log 0

Object Descriptor takeaways

A descriptor is an object which describe how the property behaves.

use object literal

Simplest way to define an object is by using object literal, by doing so, the created object are set with implicit descriptors to all "true". As illustrated below:

var objectLiteral = {
    name: 'foo'
};
set nocompatible
filetype on
filetype indent on
filetype plugin on
syntax enable
set ignorecase
set hlsearch

Why passing undefined to Immediately invoking function

(function(window, document, undefined) {...})(window, document);
  • save undefined variable from redeclearation
  • save bit from minification, since the variables will be replaced with shorter alias.
# Apache
```
/etc/init.d/apache2 start/stop/restart
```

Apache

server

/etc/init.d/apache2 start/stop/restart

folder structure

/etc/apache2/ // main folder
define(function() {
var ScriptLoader = function(url, ns, onLoadCallback, name) {
this.url = url; // url of the module
this.ns = ns; // source obj/ns obj to bind 'define' method
this.onLoadCallback = onLoadCallback;
this.name = name; // dependency name
this.load();
};
/*
* Mongoose magic
*/
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/fei');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error'));
db.once('open', function() {
var kittySchema = mongoose.Schema({
name: String

Generate take-away

Concept 1: Iterators

In computer programming, an iterator is an object that enables a programmer to traverse a container.

When invoked, generator functions return iterators

Concept 2: Run-to-completion

Run-to-completion scheduling is a scheduling model in which each task runs until it either finishes, or explicitly yields control back to the scheduler.

@geastwood
geastwood / named_function.js
Created June 26, 2014 07:17
named function
var constructor = function() {return null;};
var f = function f() {
return constructor();
};
f();
// Under ES3
// logs {}, object literal
// Under ES5