Skip to content

Instantly share code, notes, and snippets.

@johnjbarton
johnjbarton / minimalist-classes.js
Created November 13, 2011 04:34 — forked from Gozala/minimalist-classes.js
Gonzala extend with comments
// Here is a proposal for minimalist JavaScript classes(?), that does not
// introduces any additional syntax to the language, instead it standardizes
// approach already used by majority of JS frameworks today.
// !!! What is a PROBLEM!!!
function Dog(name) {
// Classes are for creating instances, calling them without `new` changes
// behavior, which in majority cases you need to handle, so you end up with
// additional boilerplate.
@johnjbarton
johnjbarton / esSubclass.js
Created November 14, 2011 21:46
Refactoring of Irakli Gonzala's extend() from git://gist.github.com/1361599.git
Object.defineProperty(Object, 'mergeDescriptors', {
value: function() {
// Shallow copy of the argument property descriptors, right most wins
//
var properties = {}
Array.prototype.slice.call(arguments).forEach(function(source) {
Object.getOwnPropertyNames(source).forEach(function(name) {
properties[name] = Object.getOwnPropertyDescriptor(source, name)
})
})
@johnjbarton
johnjbarton / backbacktick.js
Created August 7, 2012 16:55
quasi-literal vs function calls
// Comparing some of the use-cases for 'quasi-literals' aka string templates to normal functions and strings
// http://wiki.ecmascript.org/doku.php?id=harmony:quasis#syntax
x`foo${bar}baz`
// vs
x('foo',bar,'baz');
// http://wiki.ecmascript.org/doku.php?id=harmony:quasis#secure_content_generation
safehtml`<a href="${url}?q=${query}" onclick=alert(${message}) style="color: ${color}">${message}</a>`
@johnjbarton
johnjbarton / gist:8464209
Created January 16, 2014 21:56
jitsu deploy gives 500 error, here is the package.json
{
"name": "traceur",
"version": "0.0.10-1",
"description": "Experimental ES6 to ES5 compiler",
"keywords": [
"javascript",
"ecmascript",
"language",
"es5",
"es6",
@johnjbarton
johnjbarton / gist:8464796
Created January 16, 2014 22:31
jitus deploy --debug
ESC[32minfoESC[39m: Welcome to ESC[90mNodejitsuESC[39m ESC[35mjohnjbartonESC[39m
ESC[32minfoESC[39m: jitsu v0.13.9, node v0.10.4
ESC[32minfoESC[39m: It worked if it ends with ESC[90mNodejitsuESC[39mESC[1mESC[32m okESC[39mESC[22m
ESC[32minfoESC[39m: Executing command ESC[35mdeployESC[39m
ESC[32minfoESC[39m: Analyzing application dependencies in ESC[35mbuild/printSemver.jsESC[39m
ESC[34mdebugESC[39m: { method: ESC[32m'GET'ESC[39m,
ESC[34mdebugESC[39m: uri: ESC[32m'https://api.nodejitsu.com/apps/johnjbarton/traceur'ESC[39m,
ESC[34mdebugESC[39m: headers:
ESC[34mdebugESC[39m: { Authorization: ESC[32m'*********************************************************************'ESC[39m,
ESC[34mdebugESC[39m: ESC[32m'Content-Type'ESC[39m: ESC[32m'application/json'ESC[39m },
@johnjbarton
johnjbarton / gist:6a4d0871f2cc0ca9cc3d
Created May 5, 2014 17:29
Proxy fails in Object.create()
<script src="../third_party/harmony-reflect/reflect.js"></script>
<script name="testObjectCreate">
(function() {
var aPrototype = {foo: 'foo'};
var handler = {
get: function(target, name, receiver) {
console.log(' (Proxy handler \'get\' called for name = ' + name + ')');
return target[name];
}
@johnjbarton
johnjbarton / gist:f8a837104f0292fa088c
Created May 5, 2014 17:29
Proxy fails in Object.create()
<script src="../third_party/harmony-reflect/reflect.js"></script>
<script name="testObjectCreate">
(function() {
var aPrototype = {foo: 'foo'};
var handler = {
get: function(target, name, receiver) {
console.log(' (Proxy handler \'get\' called for name = ' + name + ')');
return target[name];
}
@johnjbarton
johnjbarton / gist:30c3e72d51d9d64e36d1
Created May 5, 2014 20:17
Proxy .__proto__ vs getPrototypeOf
<script src="../third_party/harmony-reflect/reflect.js"></script>
<script name="testObjectCreate">
(function() {
var aPrototype = {foo: 'foo'};
function createProxy(obj) {
return Proxy(obj, {
get: function(target, name, receiver) {
console.log(' (Proxy handler \'get\' called for name = ' + name + ')');
if (name === '__proto__')