This proposal has moved to https://github.com/sebmarkbage/ecmascript-rest-spread
// In Chrome Canary, with Experimental JavaScript enabled... | |
(function( exports ) { | |
// Create a reusable symbol for storing | |
// Emitter instance events | |
var sym = new Symbol(); | |
function Emitter() { | |
this[ sym ] = { |
The fun part of user scripting is deciding what happens. The boring part is scavenging the DOM for bits of templated data, or elements you want to mod.
Have on.js
do it for you!
(tl;dr DOM builders like [domo][domo] trump HTML templates on the client.)
Like all web developers, I've used a lot of template engines. Like most, I've also written a few of them, some of which even [fit in a tweet][140].
The first open-source code I ever wrote was also one of the the first template engines for node.js, [a port][node-tmpl] of the mother of all JavaScript template engines, [John Resig][jresig]'s [micro-templates][tmpl]. Of course, these days you can't swing a dead cat without hitting a template engine; one in eight packages on npm ([2,220][npm templates] of 16,226 as of 10/19) involve templates.
John's implementation has since evolved and [lives on in Underscore.js][underscore], which means it's the default choice for templating in Backbone.js. And for a while, it's all I would ever use when building a client-side app.
But I can't really see the value in client-side HTML templates anymore.
function range(start, end, step) { | |
step = Math.floor(Math.abs(step)) || 1; | |
if (typeof end == 'undefined') { | |
end = start; | |
start = 0; | |
} | |
else if (start > end) { | |
var s = start; | |
start = end; | |
end = s; |
### | |
Usage: $(node).shortNumber(4711) sets the contents of `node` (to "4.7k") | |
$(node).shortNumber() reads that actual number back from the node | |
If you want to pre-shorten some DOM node with a value on the server side, | |
be sure to set the data-shortNumber="4711" or whatever number on it, too: | |
Likes: <span data-shortNumber="<% _num %>"><% short_number _num %></span> | |
(To just format arbitrary numbers to tiny strings use shortNumber(4711).) |
Object.beget = (function() { | |
var create = Object.create, | |
defineProperty = Object.defineProperty; | |
// see https://gist.github.com/3194222 | |
var hasOwn = Object.prototype.hasOwnProperty.unselfish(); | |
return function beget(proto, own) { | |
var result = create(proto); |
/* vim:set ts=2 sw=2 sts=2 expandtab */ | |
/* This Source Code Form is subject to the terms of the Mozilla Public | |
* License, v. 2.0. If a copy of the MPL was not distributed with this | |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
"use strict"; | |
const { obscure, extend } = require('./heritage'); | |
const Base = extend(undefined, obscure({ |
var d = new Person('David'); | |
console.log('d.name:', d.name); | |
setTimeout(function(){ | |
console.log('d age', d.getAge()); | |
}, 500); | |
console.log('d instanceof Person', d instanceof Person); | |
console.log('d instanceof ComputerSavvyPerson', d instanceof ComputerSavvyPerson); | |
var db = new ComputerSavvyPerson('David Bruant', 'JavaScript'); | |
console.log('db.name:', db.name); |
function Namespace(common) { | |
var map = WeakMap(); | |
common = common || null; | |
function ns(object) { | |
if (Object(object) !== object) | |
return common; | |
if (!map.has(object)) { | |
var prototype = Object.getPrototypeOf(object); | |
map.set(object, Object.create(ns(prototype))); | |
} |