javascript 中 this 的指向
来源:互联网 发布:javascript选项卡代码 编辑:程序博客网 时间:2024/05/16 01:16
在函数中 this 指向 window
(function whatThis() { console.log(this);})()输出结果:
Window {speechSynthesis: SpeechSynthesis, caches: CacheStorage, localStorage: Storage, sessionStorage: Storage, webkitStorageInfo: DeprecatedStorageInfo…}
在方法中 this 指向 调用方法的对象
var object = { getThis: function() { console.log(this); }}object.getThis();输出结果:
在构造函数的实例中,this 指向 new 出的实例
var GetThis = function() { console.log(this);}var testThis = new GetThis();
输出结果:
在apply中,this 指向传入的对象
var GetThis = function(str) {}GetThis.prototype.getString = function() { console.log(this);}var obj = {str: "I can't guess this!"};GetThis.prototype.getString.apply(obj);
1 0
- javascript 中 this 的指向
- JavaScript中 this 的指向
- JavaScript中this的指向
- javascript中this的指向
- javaScript中this的指向
- Javascript中this的指向
- JavaScript中this指向
- javascript中this的指向问题
- javascript中this指向问题的综合
- JavaScript中this的指向问题
- JavaScript中this的指向问题
- javascript中this对象的指向问题
- JavaScript中this的指向问题
- 详解JavaScript中this的指向
- javaScript中关于this的指向
- javascript中this的指向详解
- JavaScript-this的指向
- javascript的this指向
- 关于android WebViewClient和WebChromeClient
- jdk8和buffterknife 冲突
- MongoDB-JAVA-Driver 3.2版本常用代码全整理(4) - 地理空间索引
- java jvm GC的基石 可达性算法
- intellij idea 出现 usage search was canceled
- javascript 中 this 的指向
- load-on-startup的使用
- mysql无法创建存储过程
- HTML+CSS基础课程之元素分类
- webView封装基类,wk/ui依据系统版本
- TYZ 8/25 送分题
- 1.Vivado HLS基本应用(流水灯)
- ubuntu 14上面安装zabbix 3.0
- VLC同时开启播放多个视频流BAT脚本