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