The various ES6-based microlibraries I've been working on recently have the following file structure:
lib/
foo/
bar.js
baz.js
foo.js
concat: { | |
amd: { | |
src: "tmp/**/*.amd.js", | |
dest: "dist/my_library.amd.js" | |
} | |
} |
module.directive("bindAttr", function() { | |
return function(scope, element, attrs) { | |
var args = JSON.parse(attrs.bindAttr); | |
for (var key in args) { | |
scope.$watch(args[key], function() { | |
var val = scope.$eval(args[key]); | |
attrs.$set(key, val); | |
}, true); | |
} | |
} |
/* | |
* grunt-neuter | |
* | |
* Copyright (c) 2012 Trek Glowacki, contributors. | |
* Licensed under the MIT license. | |
*/ | |
'use strict'; | |
var glob = require("glob"); |
// ES6 includes a new block keyword, "module", for defining modules | |
// in-line. | |
module "myModule" { | |
export default function() { | |
// You can export classes, functions, and other blocks. | |
return "Hello :)"; | |
} | |
// You can mix a default and named exports. |
<!-- Works in Chrome with "Experimental JavaScript Features" flag enabled --> | |
<html> | |
<body> | |
<span id="test"></span> | |
<script> | |
var foo = {}; | |
Object.observe(foo, function(records) { | |
records.forEach(function(record) { | |
document.getElementById(record.name).innerHTML = record.object[record.name]; |
function defaultDict(default_) { | |
return new Proxy({}, { | |
get: function(target, name, receiver) { | |
// iterator and next are two JS1.7 things Firefox looks for when you | |
// log an object to the console. pretty sure it's a bug that they trigger | |
// the get trap. | |
if (!(name in target) && !(name == '__iterator__'|| name == 'next')) { | |
target[name] = default_(); | |
} | |
return target[name]; |
var o = {}; | |
Object.observe(o, function(records) { | |
console.log(records); | |
}); | |
// the following three changes are batched, as they occur | |
// within the same frame of the loop | |
o.x = "foo"; | |
o.y = "bar"; |
var myClassCollection = []; | |
var _MyClass = function(id, foo) { | |
this.id = id; | |
this.foo = foo; | |
// some sort of arbitrary storage thing | |
this.collection[id] = this; | |
} |
post = models.Post.build({ | |
title: 'first post' | |
date: Date.now() | |
body: 'This is an autogenerated post' | |
}) | |
post.save().error((err) -> | |
console.log 'Error while saving: ' + err | |
).success(() -> | |
console.log 'Saved properly' |