I. Lexical structure
1, JS inside the case-sensitive
2. Comments are divided into two categories://single-line comment/* multiline comment */
3, the literal quantity (direct quantity Literal)
12//numeric number
"hello" ' Hello '//string
True False//boolean type
Null//null type
/js/gi//regular
{x:1,y:2}//dictionary
[1,2,3,4]//array
4. Identifiers (variables) and reserved words
5, semicolon can be omitted but may cause problems, JS will automatically complete;
Ii. types, values, and variables
1. Primitive type: number, string and boolean, null null undefined not defined
2. Object type
3, class Array Function Date RegExp Error
4. Integrated garbage collection in JS parser
5, any value of JS can be converted to a Boolean value
Undefined
Null
0
-0
NaN
"" are converted to false
6. Packaging Objects
var s = "hello"; Primitive type (no METHOD)
S.len = 4; When a property or method of the original type is called (the original type has no properties and Methods)
Whenever a property of a string is referenced, a new string (s) is called to wrap the original type into an object
Subsequent calls to S.len are properties and methods that invoke the string object, and once the reference is complete, the newly created temporary object is destroyed
var n = s.len; This is undefined
Alert (n); A temporary object that is created when a property or method of a string Boolean number is Called. is the wrapper object display defines the wrapper object
var s = new String ("hello");
var s = "hello"; Two are Different.
7, = = and = = =
8. Type Conversion
var n = 17;
Alert (n.tostring (2)); Binary 10001
Alert (n.tostring (8)); 021
Alert (n.tostring (16)); 0x21
Alert (n.tostring (10));
Alert (n.tostring ());
9, toString () Value ()
var date = new Date (2011,1,3);
Date.valueof () returns the time represented by the number of milliseconds
10, JS is a dynamic type var n = 10; Type of variable is not determined during program run
11. Scope of variables
Scope and declaration of functions in advance
Variable declarations defined within functions are automatically advanced to the top of the function
12. Scope Chain Scope chain
In a function body that does not include a function, the scope chain has two objects, the first is the object of the custom function, the parameter and the layout variable, and the second is the global object
In a nested function body, There are at least three objects on the scope chain
When a function is defined, it holds a scope chain. When the function is called, it creates a new object to store its local variables, and adds the object to the saved scope chain, while creating a new "chain" that represents the scope of the function Call. For nested functions each time an external function is called, the inner function is redefined again. The scope chain is different each time an external function is Called.
13, Delete in eval void
third, the Object
1. Basic operation of object create set query Delete Test Enumetare
2. Object property Properties Writable enumerable lesson configuration (can be Deleted)
3. Object Characteristics of objects
Prototype of the object prototype
The string of the Object's class tag object type
Three ways to add new attributes//created extensions to the team Object's extended markup
4. Direct volume of objects
var empty = {};
var point = {x:0,y:0};
5. New Object creation
var o = new Object (); Empty objects are the same as {}
var a = new Array ();
6, object.create ()
var O1 = object.create ({x:1,y:2}); O1 inherited from Object prototype {x:1,y:2}
var O2 = Object.cteate (null); O2 cannot inherit any of the property methods
var O3 = Object.create (objec.prototype); Empty objects are the same as {}new object ()
7. operation of attributes as an object of an associative array
Object.property
object["property"] hash Map Dictionary associative array
8. Inheritance
Inherited object book is null or undefined
Book.subtitle.length will make an Error.
Workaround
var len = book&&book.subtitle&&book.subtitle.lenghth;
Delete Property
Delete Book,subtitle
Detection properties in Hasownpreperty () propertyisenumerable ()
var o = {x:1};
"x" in O
"toString" in O
Hasownpreperty (); Determine whether the property is your Own. Inheritance property returns False
propertyIsEnumerable () is only a property of its own and can be enumerated
Get all the properties
Object.keys ()
Object.getownpropertynames ()
9. Attribute getter and setter
var o = {
x:o,
y:1,
Set R (value) {value = this.r;},
Get R () {return this.x + this.y;}
};
X data properties, R accessor properties
10. Attribute characteristics Ecmascript5 old IE does not support the following usage
attribute of the data attribute: value of the writable writable
Enumerable enumerable
Configurable configurable
Accessor attribute properties: Get set
Enumerable enumerable
Configurable configurable
Return {value:1,writable:true,emunerable:true,configurable:true}
object.getownpropertydescriptor{{x:1},x}
Property returned undefined not found
Setting property properties Cannot modify inherited property attributes
Object.defineproperty ()
Set non-enumerable Properties
var o = {};
Object.defineproperty (o, "x", {
value:1,
writable:true,
emunerable:false,
Configurable:true
})
Set Read-only
Object.defineproperty (o, "x", {writable:false})
modifying multiple Property attributes
Object.defineproperties ()
11. Three properties of an object
Prototype Class extensible attribute
Querying the prototype of an object
Ecmascript5 in Object.getprototypeof (o1)
ECMASCRIPT3 in O1.constructor.prototype
Objects created by object direct amount or New object ()
A property that contains a constructor that is the constructor of the object ()
Constructor.prototype can be a real prototype.
P.isprototypeof () detects if the object P is a prototype of O
Gets the type string of the object
Object.prototype.toString.call (o1). Slice (8,-1)
12. Extensibility of objects
Whether the object can be newly added to the property
Object.preventextensions () Setting object is not extensible
Object.isextensible ()
Object.seal () In addition to setting the object to not be extensible, also set the property to not be configured
Object.freeze ()
In addition to setting the object to not be extensible, set the property to not configurable, and set the property to read-only,
Iv. functions
1. Function call, method call
function T () {}
T (); Function call this is the global object in strict mode is undefined
var o = {a:function () {}};
O.a () method Call this is the object that is currently being called
2. Constructor Call
var o = new Object (); var o= new Object;
o The This object is inside the prototype property that inherits from the constructor
var r = new O.M (), in which this is not O
3. The execution of the P184 function is used in the scope chain, which is created when the function definition is Defined.
The nested function f () is defined in the scope chain, where the variable scope is a local variable
Scope chain
Calling s () creates the execution environment (the calling Object) of the function s and places the object at the beginning of the List.
It then links the calling object of the function T to the next, and finally the global Object. Then look for the variable name from the beginning of the list
Call SS () SS () ==> t () ==> window
Name= "lwy";
function T () {
var name= "tlwy";
function S () {
var name= "slwy";
Console.log (name);
}
function SS () {
Console.log (name);
}
S ();
SS ();
}
T ();
Each time a function is called, a new scope chain is Generated. Including the new internal variables
JavaScript section Summary