I've been programming in JavaScript for a couple of years, but I've never understood how different techniques work in JavaScript, only that it works..
Now, after learning properly how prototypes and constructors work, I took a look at jQuery to learn something before I set out to make my own (not publicly accessible) plugin for my own website.
The problem is just that I don't understand how it works. Here is a almost working sample: http://jsfiddle.net/3zWvR/1/
(function() {
test = function(selector) {
return new test.prototype.init(selector);
}
test.prototype = {
init: function(selector) {
alert("init ran");
if (!arguments[0]) {
return this;
}
}
}
// As I understand the jQuery code, the next line should really be
// test.prototype = {
test.prototype.init.prototype = {
send: function() {
alert("send ran");
}
}
window.ob = test;
})()
ob().send();
I've commented a line in there that shows what I think really should be there if I do it like jQuery. But I'm not able to replicate it so that you could do ob.method() either...
How is the jQuery "framework" or skeleton built and how does it work?