首页 > 编程语言 > 详细

Simulate getter in JavaScript by valueOf and toString method

时间:2014-08-17 22:39:33      阅读:365      评论:0      收藏:0      [点我收藏+]

function Foo(a, b) {
    this.a = a;
    this.b = b;

    // simulate getter via valueOf and toString method
    this.sum = {
        valueOf: function () {
            return a + b
        },
        toString: function () {
            return a + b
        }
    }
}
alert(new Foo(2, 3).sum);

Simulate getter in JavaScript by valueOf and toString method,布布扣,bubuko.com

Simulate getter in JavaScript by valueOf and toString method

原文:http://www.cnblogs.com/pengpenghappy/p/3918355.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!