码迷,mamicode.com
首页 > 编程语言 > 详细

Simulate getter in JavaScript by valueOf and toString method

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

标签:style   color   java   os   io   cti   javascript   new   

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

标签:style   color   java   os   io   cti   javascript   new   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!