UnlimitJS allows for chaining with native JavaScript objects without extending objects' prototype
s.
It has a simply API
and increases the readability of common code.
-
for inloops are safe to use - Chaining is super easy
obj[fun]()[fun]() - Unlimitjs is Javascript, no compiling
UnlimitJS intends to bring chaining and readability to Javascript.
Instead of writing: trim(' string ')
you write ' string '[trim]()
var trim = function(){
return this.replace(/^\s+|\s+$/g,'');
}[Unlimit]();
alert( ' string '[trim]() );
Here is another example
var yell = function(){
alert(''+this);
return this;
}[Unlimit]();
'Example string'[yell]()[yell]();
Examples
Unlimit isn't exactly intended for libraries to create tons of global functions like trim and yell. Unlimit is geared towards allowing methods to easily be chained without nested functions. The practicality and readability is demonstrated when you can change this jQuery snippet.
alert($.map($.trim($('input.name').val()).split(' '),function(str){
return str.replace(/[-^&]/,'');
}).join(' '));
to
// one time set up
$.trim[Unlimit](true);
$.map[Unlimit](true);
alert(
$('input.name').val()[$.trim]().split(' ')
[$.map](function(str){
return str.replace(/[-^&]/,'');
}).join(' ')
);
underscore.js + Unlimit
// Unlimit underscore.js library
for(var i in _)_[i][Unlimit](true);
[0,1,2]
// strip falsey values
[_.compact]()
[_.each](function(i){
alert(i);
})
underscore.js + Unlimit
var Mammal = function(){};
var Dog = function(){};
Dog.prototype = new Mammal();
_.extend[Unlimit](true);
Dog.prototype[_.extend]({
method:function(){},
method2:function(){}
};
API
Calling [Unlimit]()
binds the this context to the object you are calling on.
var yell = function(){
return alert(''+this);
}[Unlimit]();
'This string is bond to "this" in function.'[yell]()
Calling [Unlimit](true)
tells the object your calling on to be passed as the first argument to the function.
var yell = function(obj){
return alert(''+obj);
}[Unlimit](true);
'1st argument is bound to this string.'[yell]()
Calling object[Unlimit](function(){})
allows you to unlimit objects other then Function
s.
var yell = {};
yell[Unlimit](function(){
alert(''+this);
});
'This string is bond to the attached function.'[yell]()
Known Issues
- You can no longer decompile a function
that has been
Unlimited. In fact you shouldn't decompile a function period. It isn't cross browser and can cause bugs. -
Unlimitdoesn't work on Host Objects in IE<9. That basically means you can't expect to callUnlimited functions onNodeLists, or native DOMElements. For example this will fail in IE<9.var toArray = function(){ return Array.prototype.slice.call(this,0); }[Unlimit](); var body = document.getElementsByTagName('div')[toArray]();