JavaScript Design Patterns First Chapter notes

Source: Internet
Author: User

1.2 If Type language:
JavaScript 3 Types of elements: Boolean, numeric, String,
Object types and function types for executable code
null, undefined type.

Raw data types are passed by value, other types are passed by reference

Conversion primitive types of data types can be type cast
The 1.toString method converts a numeric value, a Boolean type, to a string
2, parsefloat, parseint function can convert a string to a numeric value
3. Double "Non" can convert string, numeric value to Boolean
var bool =!! Num


1.3 function is a one-class object
Functions are objects,
1. Variables and parameters can be passed to other functions
2. Can be returned as a return value from other functions
3. Can be constructed at run time
4. You can create an anonymous function with the function () {---} syntax
(Functon () {
var foo = 10;
var bar =2
Alert (Foot*bat) L

})();


5. The most useful use of anonymous functions is to create closures.
Closure Summary:
1. is a protected variable space, generated by the inline function.
2. Function-level scope, so the definition cannot be accessed outside the variable inside the function.
The JavaScript scope is also lexical in nature, meaning that the function runs in her definition of her scope, not in the scope of the call it, two together, you can wrap the variable in the function, and protect it, to create (private variables of the class)
var test;
(function () {

var foo = 10;
var bar = 2;
Test = function () {

return foo*bar;
}

})();


1.4, the variability of the object
1. You can add properties to a function
function DisplayError (msg) {
displayerror.numtimes++;
}
2. Modifications can be made to the previously defined classes and the instantiated underground
function Person (name,age) {
THIS.name = name;
This.age = age;

}

Prson.protype = function () {
Getname:function () {
return this.name;
}

}

Person.prototype = function () {
Getage:function () {
Return This.age
}
}
/**
* Create objects
*/

var alicer = new Person ("Alice", 40)
var bill = new Person ("Bill", 30)

/**
* Methods for modifying classes
*/

person.prototype.getGreenting = function () {
Return "HI" +this.getname ();
}

3. Introspective Concepts and reflections there is time for a good read. This concept doesn't quite understand


1.5 Inheritance

1.javascript uses a prototype object-based inheritance to emulate class-based inheritance


Summary:

The programming style and choice of design patterns used should be commensurate with the specific work to be done.

JavaScript Design Patterns First Chapter notes

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.