JavaScript design pattern expressive JavaScript (i) _javascript tips

Source: Internet
Author: User
Business:

The flexibility of 1.1 JavaScript

Object-oriented JavaScript programming mode: 1, you can save the state 2, with the object to call the method 3, the written program to master its structure, can withstand the iterative development (personally think)
Copy Code code as follows:

Enough to create a function, also known as a class
var anim=function () {
...
}
The methods in the class, the prototypes in JavaScript
Anim.prototype.start=function () {
...
}



Note: The general method is put into the prototype, because the general store in the prototype is not changed to common things

Code
Copy Code code as follows:

Function.prototype.method=function (NAME,FN) {
THIS.PROTOTYPE[NAME]=FN;
}

var anim=function () {
}
Anim.method ("Start", function () {alert ("Started")})
Anim.method ("Stop", function () {alert ("stopped")})

var anim=new anim ();
Anim.start ();
Anim.stop ();

The code above highlights a few points:

1. All function is the object of this class of function such as Var f=new function ("alert ();")

2, we can also go to the system default class prototype to add methods, but this does not advocate, easy to confuse



A function is a first-class object:

Anonymous functions can create closures (closures will open a separate chapter for learning)

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.