Skip to content

Instantly share code, notes, and snippets.

//In this way we prevent 2 things:
// 1- Polute the global scope
// 2- The creation of the array name each time digitToName is called
var digitToName = (function(digit){
var names = ['one', 'two', 'tree']
return function(){
return names[digit];
}
}());
var oldObj = {
first: function() {},
second: function() {}
};
var newObj = Object.create(oldObj);
newObj.third = function() {};
//Syntatic sugar to add methods to any function faster
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
//Example
//for any class...
function HelloClass(){
@favio41
favio41 / Javascript loggin
Created July 10, 2014 15:33
client log substitution
var log = Function.prototype.call.bind(console.log, console);
var error = Function.prototype.call.bind(console.error, console);
var info = Function.prototype.call.bind(console.info, console);
@favio41
favio41 / regex
Last active August 29, 2015 13:57
Regex usefull
Sublime regex for remove _id from export
, "_id" : \{ "\$oid" : ".*?" \}
Regex not greedy
* - zero or more
*? - zero or more (non-greedy)
+ - one or more