So I am (still) completely in love with the almighty jQuery, and I have my own growing library of utilities that I want to codify in a java-script object. And I would like to keep syntax similar to that of jquery for the sake of simplicity for my other front end devs. So I want something like this:
foo(argument).method(argument);
I have been trying something like this:
var foo = function(str){
this.str = str;
}
foo.prototype = {
alertTest : function(additional){
alert(this.str + ' ' + additional);
}
}
So that foo('hello').alertTest('world); with alert 'hello world'
I know this is possible, but I am not an OO guy and need help getting this simple thing right. Please help. I also intend on having many foo().bar(); type functions, like foo().somethingelse(); and foo().anotherthing(); . I have made several attempts, but am struggling hard here. Also there must be an awesome tight way of doing it.
Thanks folks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…