var a = function(arg)
{
if(this.a) return new a(arg);
if(arg)
{
this.arg = arg;
//code
}
}
a.prototype = {
fo: function(b)
{
alert(this.arg + b);
return this;
},
gi: function(b)
{
alert(this.arg - b);
return this;
}
}
a(5).fo(4); //9
a(7).gi(3); //4
a(5).fo(4).gi(3).fo(4).gi(3).fo(4).gi(3).fo(4).gi(3).fo(4).gi(3) //....
Вот ещё, я тут на днях эксперементировал:
var $d = document;
var $E = function(a)
{
if(this.$E) return new $E(a);
if(typeof a == 'string')
{
var b = a.substr(0,1), c = a.substr(1);
if(b == '#') this.a = $d.getElementById(c);
else if(b == '.') this.a = $d.getElementsByClassName(c);
else this.a = $d.getElementsByTagName(a);
}
else this.a = a;
}
$E.prototype = {
append: function(a)
{
if(a) for(i=0; i<this.a.length; i++) this.a[i].innerHTML += a;
return this;
},
attr: function(a, b)
{
if(a) for(i=0; i<this.a.length; i++)
{
if(typeof a == 'string' && b) this.a[i].setAttribute(a, b);
if(typeof a == 'object') for(k in a) this.a[i].setAttribute(k, a[k]);
else if(!b) return this.a[0].getAttribute(a);
}
return this;
},
delete: function()
{
for(i=0; i<this.a.length; i++) this.a[i].parentNode.removeChild(this.a[i]);
return this;
},
fade: function(a, b, c)
{
if(a)
{
var d = this, e, f;
for(i=0; i<this.a.length; i++)
{
e = e = d.a[i].style;
e.display = 'block';
e.transition = 'opacity '+(a/1000)+'s';
if(e.opacity != '0')
{
e.opacity = 0;
f = 1;
}
else e.opacity = 1;
}
setTimeout(function()
{
if(f) b ? d.delete() : d.style('display', 'none');
if(c) c(d.a);
}, a);
}
return this;
},
html: function(a)
{
if(a !== undefined) for(i=0; i<this.a.length; i++) this.a[i].innerHTML = a;
else return this.a[0].innerHTML;
return this;
},
style: function(a, b)
{
if(a) for(i=0; i<this.a.length; i++)
{
if(typeof a == 'string' && b) this.a[i].style[a] = b;
if(typeof a == 'object') for(k in a) this.a[i].style[k] = a[k];
else if(!b) return this.a[0].style[a];
}
return this;
}
}