js面向对象编程: js类定义函数时prototype和this区别?

参考文章的链接:http://www.2cto.com/kf/201406/307790.html

测试代码如下:

 1 function ListCommon2(afirst)
 2     {
 3       var first=afirst;
 4       var bbb=333;
 5 
 6       this.do1=function ()
 7        {     
 8          alert("first do"+first);
 9        }               
10        
11     }   
12 
13 ListCommon2.prototype.do2=function()
14     {     
15           //alert("first do"+first);//会出错,不能访问first
16           console.log(this);
17            var bbb = 888;
18             this.do1();
19 
20            (function do3()
21            {
22             // this.do4();
23             do4.call(this);
24            })();
25 
26             function do4()
27            {
28             alert(bbb);
29            }
30 
31     }
32 
33 var t2=new ListCommon2("烧水2");
34                 console.log(t2);
35                 t2.do1();//
36                 t2.do2();//
prototype中的一个函数访问另一个函数可以直接使用函数,也可以用 函数名.call(this),但不能用this.函数名。访问的变量也是prototype中的而不是构造函数中的。
原文地址:https://www.cnblogs.com/gavinyyb/p/6307435.html