JavaScript - the language to improve

First, the details and language skills

    1、typeof、null 和 undefined

         typeof operator to detect the data type of the variable.

         null null means "nothing" is, undefined means no value.

 

    2, data type conversion

        (1) by using JavaScript function

        (2) automatic conversion itself via JavaScript

 

    3, regular expressions

        Syntax: / regular expression subject / modifier (optional)

            Modifier comprising: i (ignore case), g (global matching), m (multiple line matches).

        Common methods: search () and replace ().

 

    4, lifting (Hoisting)

        Variable lift: declare variables will be promoted to the top most scope, note that only a statement would be promoted to enhance not be defined.

        Enhance the function: Declare Function / definitions will be promoted to the top of the scope.

 

    5, strict mode (use strict)

        Effect: the elimination of some of the insecurity code to run, to ensure safe operation of the code; the compiler to improve efficiency, increase speed; pave the way for future new version of Javascript.

        Add keywords strict mode: implements, interface, let, package, private, protected, public, static, yield.

 

    6, JavaScript built-in objects, attributes and methods

 

Array Date eval function hasOwnProperty
Infinity isFinite isNaN isPrototypeOf length
Math NaN name Number Object
prototype String toString undefined valueOf

 

    7, this keyword

        In the method, this method indicates that the object belongs.

        If used alone, this represents a global object window.

        In function, this represents a global object window. (In function in strict mode, this is undefined (undefined).)

        In the event, this represents an element receiving the event.

 

    8, let and const

        ES2015 (ES6) adds two important new JavaScript Keyword: let and const.

        Let variables declared valid only within the block where the let command, it actually increases the global scope and outside the scope function of the local code block scope.

        const declare a constant read-only, once declared value of the constant can not be changed.

 

    9、void

        To calculate the void keyword specifies an expression but does not return a value.

        For example, javascript: void (0) does not make sense.

 

Two, JavaScript function

    1, the function definition

        Using a function declaration: function myfunc (a, b) {return a * b;}

        Function expression (anonymous function): var myfunc = function (a, b) {return a * b;}

        Use Function () constructor: var myfunc = new Function ( "a", "b", "return a * b")

 

    2, function parameters

        Explicit parameter (the Parameters, i.e., formal parameters), a hidden parameter (the Arguments, i.e. arguments).

        You do not specify the data type explicitly defined parameters. Implicit function type parameter is not detected, the number of implicit parameter is not detected.

        ES5 if the function is not available when you call an implicit parameter, parameter default setting is: undefined.

        ES6 supports functions with default parameters.

        JavaScript functions have a built-in objects arguments object that contains the parameter array function call.

        JavaScript implicit argument passed by value: the value of the function just acquired, the parameters implicit change is not visible outside the function.

 

    3, function calls

        As a global function call, then this points to the window object.

        As an object method call, then this points to the object.

        Use constructor to call the new function will generate a new function object, this case does not point to any value.

        To function object via the call () and apply () two methods, which require the first object as a parameter in this case points to the first parameter value.

 

    4, closure

        Function can access local variables, global variables may be accessed; and when the function inlining, local variables inline access to the external function can also access global variables.

        Create a function object inside the function, the function object to access the local variables of the outer function.

        The creation of this internal function object is returned, it can operate only through private local variables of the outer function, this mechanism is closure.

 

Three, JavaScript objects

    1, the object basis

        JavaScript does not like the concept, the concept is similar to the object, the object but also the concept of inheritance. (For ... in time to traverse the object will traverse the properties of the object)

        Everything in JavaScript is an object, the object has properties and methods; all JavaScript objects inherit properties and methods from a prototype (prototype object) in.

        There are three ways to create objects:

            (1) var obj = new Object(); obj.name = "java"; obj.color = "red";

            (2) var obj = {name: "java", color: "red"};

            (3) 对象构造器: function func(name, color) { this.name = name; this.color = color} | var obj = new func("java", "red");

        JavaScript Object Manual:  https://www.runoob.com/jsref

 

    2, Number objects

        属性: MAX_VALUE、MIN_VALUE、NEGATIVE_INFINITY、POSITIVE_INFINITY、NaN、prototype、constructor。

        方法: toExponential()、toFixed()、toPrecision()、toString()、valueOf()。

 

    3, String objects

        属性: length、prototype、constructor。

        方法: charAt()、charCodeAt()、concat()、fromCharCode()、indexOf()、lastIndexOf()、match()、replace()、

            search()、slice()、split()、substr()、substring()、toLowerCase()、toUpperCase()、valueOf()。

 

    4, Boolean objects

        In the determination logic, the value will be identified as to false: 0, -0, null, "", to false, undefined, NaN3.

        Properties: prototype, constructor.

        方法: toString()、valueOf()。

 

    5, Array Objects

        Use var x = new Array (); to create different array subscript points may be different types of objects.

        属性: length、prototype、constructor。

        方法: concat()、...、toString()、valueOf()。

 

    6, Date Object

        Properties: prototype, constructor.

        方法: getDate()、...、toString()、valueOf()。

 

    7, Math Object

        Properties: E, LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2, SQRT2

        Method: abs (x), ..., sqrt (x), tan (x).

 

    8, RegExp objects

        属性: global、ignoreCase、lastIndex、multiline、source、constructor。

        方法: compile()、exec()、test()、toString()、search()、match()、replace()、split()。

 

Guess you like

Origin www.cnblogs.com/ringboow/p/11118553.html