[英]This in function inside object Javascript
此代碼有什么問題,功能fullAdress我不知道我的代碼有什么問題,請幫助我修復
var person = { firstName: 'Ammar', lastName: 'Gais', age:21, adress:{ street:'king road', city:'atabra', state:'River Nile' fullAdress: function(){ return this.street+" "+this.city+" "+this.state; } }, fullName: function() { return this.firstName+" "+this.lastName; } }
您在'River Nile'
之后缺少逗號。 始終建議您在瀏覽器控制台中查看此類錯誤。 即使對象具有屬性或方法,也應將所有內容用逗號分隔:
var person = { firstName: 'Ammar', lastName: 'Gais', age: 21, adress: { street: 'king road', city: 'atabra', state: 'River Nile', fullAdress: function() { return this.street + " " + this.city + " " + this.state; } }, fullName: function() { return this.firstName + " " + this.lastName; } } console.log(person.adress.fullAdress()); console.log(person.fullName());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.