__x__(64)0925第十天__ JavaScript 对象的 toString() 方法改变输出

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

在平常,我们 console.log(对象);    // 会打印 [Object Object]

但是我们想要更详细的输出,此时,我们可以重写 对象.toString() 方法


  • Person.toString = function(){
                                     return "Person ["+this.name+" , "+this.gender+","+this.age+"]";
                                }

 

猜你喜欢

转载自www.cnblogs.com/tianxiaxuange/p/9703599.html