Skip to content

Instantly share code, notes, and snippets.

View xcambar's full-sized avatar

Xavier Cambar xcambar

View GitHub Profile
@xcambar
xcambar / module1
Created September 27, 2012 09:43
basic Harmony module
Module dynamicList {
import xhr from '/dataSources.js'; // dataSources is another module
import template at '/tpls/list.js';
var classNames = ['dynamic', 'vertical'];
var refreshInterval = 300000; //ms
var run = function (rootElt, params) {
return setInterval(function () {
xhr.get('/list', params, function (data) {
template.compile(data, rootElt, {classes: classNames});
@xcambar
xcambar / gist:3792881
Created September 27, 2012 08:26
Object Literal
var i = {
a : function () { },
BASE_VALUE: 42
}
@xcambar
xcambar / gist:3792865
Created September 27, 2012 08:22
Module Pattern
var AdamsModule = (function (foo, bar) {
var theAnswer = 42;
var questionFromAnswer = function () { /** ? **/ };
return {
getTheAnswer : function () { return theAnswer; },
computeQuestion : function () {
questionFromAnswer(this.getTheAnswer());
}
}
})(foo, bar)
@xcambar
xcambar / esharmony-export-confilcts
Created March 7, 2012 00:34
ECMAScript Harmony - conflicting states in grammar
Program ::= ProgramElement*
ProgramElement ::= Statement
| VariableDeclaration
| FunctionDeclaration
| ImportDeclaration
| ExportDeclaration
| ModuleDeclaration
ModuleSpecifier ::= StringLiteral | Path
ModuleDeclaration ::= "module" Id "at" String ";"
@xcambar
xcambar / string_prototype_extension_fail.js
Created October 18, 2011 08:44
String prototype extension fail!
/**
* Comparing a String object and a simple string
**/
var myStringSimple = 'abcd';
console.log(myStringSimple instanceof String); // false
console.log(typeof(myStringSimple)); // 'string'
var myStringObject = new String('abcd');
console.log(myStringSimple instanceof String); // true