我对作为类的函数中的return语句感到困惑。请参阅下面的示例代码:函数返回语句作为类
<html>
<body>
<script type="text/javascript">
function test() {
this.abc = 'def';
return 3;
}
var mytest = new test();
document.write(mytest + ', ' + (typeof mytest) + ', ' + mytest.abc);
</script>
</body>
</html>
代码输出:[object object],object,def。
这是我的问题。我在test()函数中写了'return 3'。当'new test()'被调用时,这个语句是否被忽略?
感谢。
JavaScript没有类。 js中的对象基于原型... – Ivan 2011-01-22 19:34:47