Possible Duplicate:
Use of ‘prototype’ vs. ‘this’ in Javascript?
I am reading this blog post about making JS frameworks. I am familiar (to an extent) with the concepts of ECMA prototype, and scope and closures in general. However I'm not confident that I am sure about the ins and outs of code like the following:
var myFramework = (function (window, document) {
var /* Global variables */
myFramework = function (el, options) {
// code
};
myFramework.prototype = {
// code
};
return myFramework;
})(window, document);
I understand why window and document are being passed (to save on resources, as explained in this video). What boggles me especially is why is it necessary to have both myFramework = function () {}
and myFramework.prototype
? What is it for? Why not use this
declarations inside myFramework = function () {}
instead?