我在es6中编写代码并使用了调用方法,但其他参数未传递,则显示未定义

时间:2018-07-13 09:29:01

标签: javascript

const  msg1 = {
    fname:'Divyesh',
    lname:'Patel',
}
const person = {
 fullname : function(city,num)
    {
        return this.fname+ " " + this.lname+" "+ this.city +" "+ this.num ;       
    }
}
console.log(person.fullname.call(msg1,"Surat","972737")); 

输出: Divyesh Patel未定义未定义

我在es6中编写了代码,并使用了调用方法,但未传递其他参数,显示未定义

1 个答案:

答案 0 :(得分:0)

 const msg1 = {
      fname: 'Divyesh',
      lname: 'Patel',
    }
    const person = {
      fullname: function (city, num) {
        return this.fname + " " + this.lname + " " + city + " " + num;
      }
    }
    console.log(person.fullname.call(msg1, "Surat", "972737"));