太久没写JS了,但也不至于这么简单的代码也会出错, 实在是想不通错在哪里function test(){return test;}
test.prototype = {
show : function(f){alert(f)}
}
(new test()).show('d');
报错的是test.prototype = {  这一行,说缺少函数。

解决方案 »

  1.   

    function test(){return this;}
    test.prototype = {
        show : function(f){alert(f)}
    }
    new test().show('d');
      

  2.   

    function test() {return test;}
    Function.prototype.show = function(f) { alert(f); }
    var x  = new test();
    (new test()).show('d');
      

  3.   

    function test(){return this;}
    test.prototype = {
        show : function(f){alert(f)}
    }
    new test().show('licai1210');
    //(new test());别乱用,各种执行,理解了就好了,如果加了()就不再是new test()对象了,应该是object对象了
    alert(typeof((new test())))会告诉你答案
      

  4.   

    function test(){}
    test.prototype = {
        show : function(f){alert(f)}
    }
    var a = new test();
    a.show('d');这样就好了