<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type='text/javascript'>
var Persons = function() {
return function() {};
};var persons = new Persons;
var persones = Persons();
//var _persons = new persons;
//alert(person.__proto__.constructor);
//alert(persons.__proto__.constructor);
//alert(_persons.__proto__.constructor);
//alert(persones.__proto__.constructor);
//alert(Person.__proto__.constructor);
alert(persons instanceof Function);
alert(persones instanceof Function);
</script>
</head><body>
</body>
</html>
两者的区别是?

解决方案 »

  1.   

    以前有人问过类似的问题,你可以去翻一翻。你要是把它当成一个构造函数(类),你就不要用return
      

  2.   


    var func = function() {};
    var Persons = function() {
    return func;
    };
    var persons = new Persons;
    var persones = Persons();
    alert(persons === persones);测试证明没区别
      

  3.   

    当一个构造函数(类)return的返回值是个对象(包括Object,Array,Function),则用这个对象代替构造函数创建的实例对象this返回给调用者。