学习笔记:JS修改toString()的返回中i

// 修改toString()的返回值。

function Person(name, age, gender) {

    this.name = name;

    this.age = age;

    this.gender = gender;

    this.show = function() {

        console.log("你的姓名是:" + name + ";你的年龄是:" + age);

    }

}

Person.prototype.story = "西游记";

Person.prototype.sayHello = function() {

    console.log("我喜欢看" + this.story);

};

Person.prototype.toString = function() {

    return "Person[name=" + this.name + ";age=" + this.age + ";gender=" + this.gender + "]";

};

var person = new Person('孙悟空', 1000, '男');

console.log(person.hasOwnProperty("西游记"))

console.log(person.toString());

上一篇:Java打印对象信息


下一篇:node.js热重载,包括运行报错解决方法