Skip to content

Instantly share code, notes, and snippets.

Justin Meyer justinbmeyer

View GitHub Profile
@justinbmeyer
justinbmeyer / newmvc.md
Created Dec 5, 2011
What's new in JavaScriptMVC Lately
View newmvc.md

The following is a quick overview of what's going on with JMVC since 3.0:

Deferreds

$.Model and $.View both support deferreds. Allowing super sexy code like:

$('#recipes').html('recipes.tmpl', Recipe.findAll() );
View recipejs.md

Class

Classes are used to simplify JavaScript constructor creation. Both $.Controller and $.Model extend $.Class.

$.Class $.Class([name,] [classProperties,] [prototypeProperties])

To create a Class class of your own, call $.Class.extend with the:

  • name of the class which can be used for introspection,
  • classProperties that are attached directly to the constructor, and
@justinbmeyer
justinbmeyer / gist:1601981
Created Jan 12, 2012
You need a client-side dependency management and build system.
View gist:1601981

You need a client-side dependency management and build system. What I mean by this is:

A client-side script loader that does dependency management and can package your scripts for rapid download.

There are only 2 that I'm aware of that qualify are RequireJS and StealJS. There are 3 reason to use these systems:

  • Easy, Parallel, Isolated Development
  • Integrated Build Systems
  • They work on every system
View my$.js
(function(){
var my$ = function(selector){
if(!(this instanceof my$)){
return new my$(selector);
}
if(typeof selector === 'string'){
var arrayOfElements = my$.makeArray( document.querySelectorAll(selector) );
View Rapid Start.js
steal('jquery/model',
'jquery/dom/fixture',
'jquery/view/ejs',
'jquery/controller/route',function(){
$.fixture("GET /services/todos.json", function(){
return [200,"success",[
{id: 1,
name: "wake up"},
View fixture.js
$.fixture("/searchresults", function(options){
var countries = [{
id: 1,
name : "Apple"
}]
if(!options.data.q){
return [countries];
}
View paginate.js
steal('jquery/controller', 'jquery/model', function() {
$.Model("Paginator", {
defaults: {
limit: 100,
offset: 0,
count: Infinity
}
}, {
@justinbmeyer
justinbmeyer / enum.md
Created Mar 28, 2012
Enums in JavaScript
View enum.md

Reasons to Use Enums:

  1. Easier to Debug / more likely to give errors.
  2. Can look up available properties.
  3. Property values changes.

Lets break each of these down:

Easier to debug / more likely to give errors

@justinbmeyer
justinbmeyer / fastfix.js
Created Apr 13, 2012
Makes jQuery.event.fix fast
View fastfix.js
(function(){
var set = function(obj, prop, val){
Object.defineProperty(obj,prop,{
value : val
})
return val;
};
View requireideal.md

There's so many things wrong with the world of script loading today. I want an easy way to:

  • install locally scripts and their dependencies
  • load these scripts from my application

I want it to:

  • work readily with almost all existing projects, source that does not use the script loader
  • handle versioning
  • have as few configs as possible
You can’t perform that action at this time.