企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~javascript 1.var fullName='language'; 2.var obj={ 3. fullName: 'javascript', 4. prop:{ 5. getFullName:function(){ 6. return this.fullName; 7. } 8. } 9.}; 10.console.log(obj.prop.getFullName()); 11.var test=obj.prop.getFullName; 12.console.log(test()); ~~~ ~~~javascript 1.var name='window'; 2.var Tom={ 3. name:"Tom", 4. show:function(){ 5. console.log(this.name); 6. }, 7. wait:function(){ 8. var fun=this.show; 9. fun(); 10. } 11.}; 12.Tom.wait(); ~~~ ~~~ /* * 1.元素绑定事件,方法中的this是当前操作的元素 * 2.方法名前面是否有点,有点,点前面是谁this就是谁,没有this是window(严格模式下是undefined) * 3.构造函数执行,方法体中的this是当前类的一个实例 * * 你以为你以为的就是你以为的 */ /* var fullName = 'language'; var obj = { fullName: 'javascript', prop: { getFullName: function () { return this.fullName; } } }; console.log(obj.prop.getFullName());//=>this:obj.prop =>obj.prop.fullName =>undefined var test = obj.prop.getFullName; console.log(test());//=>this:window =>window.fullName =>'language'*/ /* var name = 'window'; var Tom = { name: "Tom", show: function () { console.log(this.name); }, wait: function () { var fun = this.show;//=>Tom.show fun();//=>this:window =>window.name =>'window' } }; Tom.wait();//=>this:Tom */ ~~~ ![](https://img.kancloud.cn/dc/c5/dcc5a056c1145b5f7ec63d226c6c2660_544x245.png) ~~~javascript 1.function fun(){ 2. this.a=0; 3. this.b=function(){ 4. alert(this.a); 5. } 6.} 7.fun.prototype={ 8. b:function(){ 9. this.a=20; 10. alert(this.a); 11. }, 12. c:function(){ 13. this.a=30; 14. alert(this.a) 15. } 16.} 17.var my_fun=new fun(); 18.my_fun.b(); 19.my_fun.c(); ~~~