麻烦各位大虾,帮我看看这个代码,为什么红色部分不能调用?

// 获取一个类typeof的方法 function getType(x) { if(x == null) return "null"; var t = typeof x; if (t != "object") {return t;} var c = Object.prototype.toString.apply(x); //[object Class] c = c.substring(8, c.length-1); // [Class] if (c != "Object") return c; if(x.constructor == Object) return c; if ("classname" in x.constructor.prototype && typeof x.constructor.prototype.classname == "string" ) return x.constructor.prototype.classname; } //从一个类中复制方法到另一个类中 function borrowMethods(borrowForm,addTo) { var from = borrowForm.prototype; var to = addTo.prototype; for (m in from) { if(typeof from[m] != "function") continue; to[m] = from[m] } } //test的构造函数 function test(name) { this.name = name; } //为test原型添加方法,一种是直接调用getType()方法,一种是把getType()方法直接复制到test中 test.prototype.gettype= function() { [color=red]//getType.call(this,(new test())); getType.call((new test()),(new test())); borrowMethods(getType,test);[/color] } alert((new test()).gettype); //去掉"()"这种写法只是表示取对象的值,而不是调用方法,因为方法本身也就是一种属性。

[code="javascript"]
alert((new test()).gettype);
[/code]
这个只是对该方法的一个引用,自然打印出来的就是gettype函数本身的内容了。如果改成[code="java"script]alert((new test()).gettype());[/code]这样才会发起函数调用,自然才能知道红色部分是否执行了,返回值是“undefined”是正确的,因为函数没有明确的返回值。
如果你要知道红色部分是否调用了,在getType里面设置断点就可以看到,或者里面加个什么alert之类的语句。

支持楼上的说法