What is the `name` keyword in JavaScript?

前端 未结 4 678
温柔的废话
温柔的废话 2020-12-03 17:23

When I typed this apparently innocent snippet of code:

values.name

gedit highlighted name as a keyword. However,

4条回答
  •  孤城傲影
    2020-12-03 17:38

    This happened to me also, for example, the following didn't work for me while I was testing the call, bind functions.

    var name={
    firstname: 'Abhishek',
    lastname: 'Agarwal',
    
    fullname: function{
        var fname = this.firstname + ' ' + this.lastname;
        return fname;
    }
    
    function printname(){
        console.log(this.fullname());
    }
    var final=printname.bind(name);
    final();
    

    This didn't actually perform the task and instead when I replaced "name" occurences by "myname" or literally anything else, it did work!

提交回复
热议问题