Onwards
A recent project that uses JavaScript as a dynamically generated script for a page, using JSON to communicate with the server. Before reading the legacy code, often will not be clear, scope, this keyword in the current context of the point, and so then began to learn the relevant knowledge, recorded down to share with you.
Here are some of the code, suggesting that you also try to modify and understand, so it is easier to master. Click here to download the source code involved.
Prototype
JavaScript is a prototype based programming language, which differs greatly from our usual class based programming, and I enumerate the important points as follows:
1. The function is a class object, which means that the function has the same language status as the object.
2. No class, only objects
3. Function is also an object, the so-called function object
4. Objects are passed by reference
So how does this prototype based programming language achieve inheritance (an essential element of OO), which is the origin of prototype.
Look at the following code fragment:
function foo(a, b, c)
{
return a*b*c;
}
alert(foo.length);
alert(typeof foo.constructor);
alert(typeof foo.call);
alert(typeof foo.apply);
alert(typeof foo.prototype);