Home > Web Front-end > JS Tutorial > An in-depth analysis of JavaScript's in-depth and easy-to-understand problems

An in-depth analysis of JavaScript's in-depth and easy-to-understand problems

零到壹度
Release: 2018-04-02 16:30:26
Original
1449 people have browsed it

This article shares with you an in-depth analysis of JavaScript's in-depth and simple operation details. The content is quite good. I hope it can help friends in need.

1. Function actual Passed parameters can be obtained through arguments.

2.arguments is an array-like object, and the prototype is not Array.prototype, so there are no array methods such as join;

3.foo(1,2), arguments[2] Because no parameters are passed in, the binding relationship is lost,

foo(x,y,z){
arguments[1]=12  //y=12
arguments[2]=13;//z仍然未定义
}
foo(1,2);
Copy after login

But if it is in strict mode, arguments are always a copy of the parameters passed in, so the actual parameters cannot be modified; and arguments.calle is also prohibited from being used. of.

4.

this.x=9;
    var module={
        x:81,
        getX:function(){
            console.log(this.x);
        }
    };
    module.getX();
    var getX=module.getX;//将module的属性赋给getX变量
    getX();//这时候的this应该指向全局变量
    //为了理解,个人认为也可以看做getX=function(){return this.x;} getX()
    var boundGetX=getX.bind(module);//绑定module对象
    boundGetX();
Copy after login

5.bind has the function of currying, binding some parameters, and then only needs to pass in the remaining parameters

function add(a,b,c){
    console.log(a+b+c);
   }
    var func=add.bind(undefined,100);//this暂时是undefined
    func(1,2);
    var func2=func.bind(undefined,200);//注意这里是func
    func2(10);
Copy after login

Note that in new, bind will be ignored, because the prototype is returned as an empty object of the prototype attribute of the new constructor (if there is no returned object)

function foo(){
        this.a=100;
        return this.b;
    }
    var func=foo.bind({b:2});
    console.log(func());//2
    var o=new func();
    console.log(o);//foo {a: 100}
Copy after login

6.bind method simulation ( Leave it aside for now)


Related recommendations:

JavaScript in simple terms

First introduction to JavaScript in simple terms

JavaScript in simple terms (advanced)

The above is the detailed content of An in-depth analysis of JavaScript's in-depth and easy-to-understand problems. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template