JavaScript must know the prototype

Source: Internet
Author: User

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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.