JavaScript Advanced Programming Version 3rd notes

Source: Internet
Author: User
Tags variable scope

<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

    1. The first parameter is the object that needs to be set
    2. The second parameter is the object property name;
    3. 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

Related Article

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.