How do I create a prefix like the one jQuery uses? For example, in jQuery I can use:
$(".footer").css('display', 'none');
and I'd like to enable a similar syntax, like this:
google('.footer').chrome('display', 'none');
I have searched Google for an answer, but couldn't find it.
You have a detailed explanation here
But the right way to implement is show bellow:
var google = function(valor){
var lalala = '3';
this.chrome = function(valor){
console.log(lalala + ' ' + valor);
return this;
}
this.firefox = function(valor){
console.log(lalala + ' ' + valor);
return this;
}
console.log(valor);
return this;
};
console.log('first call');
google('testando').chrome('stack');
console.log('second call');
google('testando').chrome('stack').firefox('test');
As you could see the key is to return the object itself on each function.
You could see the live code at jsbin.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With