<script src = "xxx.js" defer = "defer" > </script>
When referencing external script, <script src = "" > Internal no more code, the browser only loads external files </script>
The defer property is only useful for external JS reference scenarios; The attribute function specifies to download the JS code until the content of the page is loaded and the JS file is loaded;
Variable scope
- A can only access a
- B can only access A, b
- C can only access A, B, c
- D can only access a, D
There is no block scope in JavaScript, only function scope
for (var i = 0; i < i++)
{
......
};
Alret (i); i = the scope of the 9;//i belongs to the upper scope;
Variables declared with Var are automatically placed in the nearest scope (inside the function), without using Var declared variables. Are global variables
Data type
Base type (undefined, Null, Boolean, number, String)
Reference type (Object, Array, Date, RegExp, Function,)
var obj = new Object ();
var arr = new Array ();
var arr = new Array (5); Allocation length
var arr = new Array ("Init", "init1"); Create and initialize
var time = new Date (); Returns the current system time
var re = new RegExp (); Regular expression type
Math Object
Value of Math.PI//Pie
Math.max ("5", "4", "8", "...");//returns the maximum value (which can be understood as a static member method)
Math.min ("...");//returns the maximum value
Object
Object.defineproperty (obj, "name", {
Writable:false,
Value: "Bokeyuan"
});
Object.defineproperty (); Static member function to specify the member property type
- The first parameter is the object that needs to be set
- The second parameter is the object property name;
- The third object is the object property type setting
Types that can be set
- [Configurable]//can delete properties via Delete, default true
- [Enumerable]//can return the property by For-in loop by default True
- [Writable]//can modify the property value by default True
- [value]//read from the location of the property value, when writing a value, put in this position, the default undefined;
Creating objects
Factory mode (function call mode)
function getobj (name, face, Toll)
{
var obj = new Object ();
Obj.name = name;
Obj.face = face;
Obj.toll = toll;
Member Methods
function Ta ()
{
return face + toll;
}
....
return obj;
}
var a1 = Getobj ("...", "...", "...") ");
var a2 = Getobj ("...", "...", "...") ");
Constructor mode (function object equivalent mode)
function Getobj (name, age, Time)
{
THIS.name = name;
This.age = age;
This.time = time;
function T ()
{
return this.time++;
}
}
var obj = new Getobj ("...", "...", "...");
Prototype mode (member initialization mode)
function Getobj ()
{
GetObj.prototype.name = "...";
GetObj.prototype.age = ....;
GetObj.prototype.time = ....;
function X ()
{
.....
}
}
var obj = new Getobj ();
Combining constructor Mode with
Dynamic Prototyping Mode
Parasitic constructor mode
Secure constructor Mode
Inherited
Prototype chain
Borrowing constructors
Combining inheritance
Prototype inheritance
Parasitic inheritance
Parasitic combined inheritance
JavaScript Advanced Programming Version 3rd notes