(64)Wangdao.com第十天_JavaScript 对象的 toString() 方法改变输出

JavaScript 对象的 toString() 方法改变输出this

在日常,咱们 console.log(对象);    // 会打印 [Object Object]spa

可是咱们想要更详细的输出,此时,咱们能够重写 对象.toString() 方法code


  • Person.toString = function(){
                                     return "Person ["+this.name+" , "+this.gender+","+this.age+"]";
                                }
相关文章
相关标签/搜索