JS Object-oriented 5-clock notation _js object-oriented

Source: Internet
Author: User
Java code
Copy Code code as follows:

The 1th Way of writing
function Circle (r) {
THIS.R = R;
}
Circle.pi = 3.14159;
Circle.prototype.area = function () {
return CIRCLE.PI * THIS.R * THIS.R;
}
var c = new Circle (1.0);
Alert (C.area ());

Java code
Copy Code code as follows:

The 2nd Way of writing
var Circle = function () {
var obj = new Object ();
Obj. PI = 3.14159;
Obj.area = function (r) {
return this. PI * R * r;
}
return obj;
}
var c = new Circle ();
Alert (C.area (1.0));

Java code
Copy Code code as follows:

The 3rd Way of writing
var Circle = new Object ();
Circle.pi = 3.14159;
Circle.area = function (r) {
return this. PI * R * r;
}
Alert (Circle.area (1.0));

Java code
Copy Code code as follows:

The 4th Way of writing
var circle={
"PI": 3.14159,
' Area ': function (r) {
return this. PI * R * r;
}
};
Alert (Circle.area (1.0));

Java code
Copy Code code as follows:

The 5th Way of writing
var Circle = new Function ("this. PI = 3.14159;this.area = function (r) {return r*r*this. PI;} ");
Alert ((New Circle ()). Area (1.0));

Let's talk about these five kinds of writing, their advantages and disadvantages, which comparison norms, especially the last two, often seen.

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.