每当通过new关键字执行一个函数,一个新的对象就会被创建出来,并被用作函数内部的上下文。
<html><head><title></title>
<script type="text/javascript">
    var Adder = function(valueA , valueB) {
        var newvalue = valueA + valueB;
        this.value = newvalue;
        this.result = function() {alert(this.value)};
    };
    var added = new Adder(5,6);
    added.result;
</script></head><body></body></html>
我写的一段代码怎么什么都没有啊?不是应该执行一个result函数弹出11的信息框吗?还有在构造函数中返回对象也不能实现
<html><head><title></title>
<script type="text/javascript">
    var Adder = function(valueA , valueB) {
        var newvalue = valueA + valueB;
        var object = new Object();
        object.result = function() {alert(this.value)};
        return object;
    };
    var added = new Adder(5,6);
    added.result();
</script>
</head><body></body></html>