// I'm not using any pattern here, for the sake of simplicity :)
// remember, it needs jquery
'use strict';
var app = {};
app.appView = function() {
// gets new class and attatchs an custom event to it
var newClass = new app.myNewClass();
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function curry(fn) { | |
var slice = Array.prototype.slice, | |
stored_args = slice.call(arguments, 1); | |
return function() { | |
var new_args = slice.call(arguments), | |
args = stored_args.concat(new_args); | |
return fn.apply(null, args); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var App = App || {}; | |
Module = function(ns_string) { | |
var parts = ns_string.split('.'), | |
parent = App, | |
i; | |
if(parts[0] == 'App') { | |
parts = parts.slice(1); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Sandbox() { | |
var args = Array.prototype.slice.call(arguments), | |
// last arg is the callback | |
callback = args.pop(), | |
// gets all modules beeing passed as different args, or as an Array | |
modules = (args[0] && typeof args[0] === 'string') ? args : args[0], | |
i; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Constr = (function() { | |
var id = 0; | |
function cl() { | |
this.id = id += 1; | |
} | |
cl.prototype.getId = function() { | |
return this.id; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var constant= (function() { | |
var allowed = { | |
string: true, | |
number: true, | |
boolean: true | |
}, | |
ownProp = Object.prototype.hasOwnProperty, | |
constants = {}, | |
prefix, | |
isDefined; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var device = navigator.userAgent.toLowerCase(); | |
if(device.indexOf('mac') != -1) { | |
console.log('É um mac'); | |
} else if(device.indexOf('iphone') != -1) { | |
console.log('É um iphone'); | |
} else if(device.indexOf('android') != -1) { | |
console.log('É um iphone'); | |
} else { | |
console.log('Não identificado'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// with this extend method, the second object is created, but there is no object reference between them. | |
var extend = function(parent, child) { | |
var i = 0, | |
child = child || {}, | |
toStr = Object.prototype.toString, | |
arrayRef = '[object Array]'; | |
for(i in parent) { | |
if(parent.hasOwnProperty(i)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// can be used for browsers that doesn't have "bind" implemented | |
if(typeof Function.prototype.bind === 'undefined') { | |
Function.prototype.bind = function(thisArgs) { | |
var slice = Array.prototype.slice, | |
args = slice.call(arguments), | |
fn = this; | |
return function() { | |
return fn.apply(thisArgs, args.concat(slice.call(arguments))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var CarMaker = function() {}; | |
CarMaker.prototype.drive = function() { | |
return 'My car has ' + this.wheels + ' wheels'; | |
}; | |
CarMaker.factory = function(type) { | |
var car; | |
if(typeof CarMaker[type] !== 'function') { |
OlderNewer