Skip to content

Instantly share code, notes, and snippets.

@jensarps
Created September 16, 2011 08:55
Show Gist options
  • Save jensarps/1221611 to your computer and use it in GitHub Desktop.
Save jensarps/1221611 to your computer and use it in GitHub Desktop.
EmbedJS code examples
// DOM node creation quick'n'easy:
var containerNode = embed.create('div', {
className: 'container box',
innerHTML: '<span>Huh, a container!</span>',
style: {
border: 'solid red 1px'
}
}, parentNode);
// Async made easy – CommonJS compliant Promises with EmbedJS:
var doAsyncOperation = function(){
var promise = new embed.Promise();
setTimeout(function(){ // simulate some asnyc operation…
if(operationWasSuccessful) {
promise.resolve(someResult);
}else {
promise.reject(someError);
}
}, 500);
return promise;
}
// And use it like this:
doAsyncOperation().then(onSuccessCallback, onErrorCallback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment