1. Scope of this in objects:
var b = {a:outerFunc, b:"b"}
function outerFunc(base) {
var outer=this;
var punc="!";
function returnString(ext) {
//console.log(this===outer);
console.log(outer);
console.log(this);
return base + ext + punc;
}
return returnString;
}
var baseString = b.a("Hello ");// method 'a' is called from the scope of object 'b', 'this' refer to the object of 'b'
, so outer will be assigned object 'b'
baseString("World"); //baseString is called from the window scope, the 'this' in the mothod of 'returnString' now
refer to the window object
var o={}; // declaring new object
o.name="moon";
o.method=function () {
alert(this.name);
};
var x={};
x.name="sun";
x.method=o.method;
x.method();//Alert sun here
var o={}; // declaring new object
o.name="moon";
o.method=function () {
alert(this.name);
};
var x={};
x.name="sun";
o.method.call(x);//alert "sun here"
// For more, refer to http://devign.me/javascript-this-keyword/
2. this in Html elements:
http://www.quirksmode.org/js/this.html
3. A more detailed introduction can be found here.
http://justin.harmonize.fm/index.php/2009/09/an-introduction-to-javascripts-this/
分享到:
相关推荐
Presentations-JavaScriptThis-源码.rar
JavaScript中this的指向还没搞明白?来这看看 你就懂啦~
这篇文章主要介绍了JavaScript this使用方法图解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 本文我们介绍下js中this的用法。 由上图可得,默认this指向...
Study note on htis keyword in JavaScript
本文对Javascript this函数进行详细介绍,及知识的总结整理,彻底明白js this 函数该如何使用。 this 代码函数调用时, .1直接调用函数则为this则指向window对象 .2类调用时候指向这个类 .3 方法.apply(obg) ;...
这篇文章主要介绍了JavaScript This指向问题详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 各位小伙伴在面试中被面试官问道this指向问题一定不少吧,同时...
本文实例形式详细分析了JavaScript this绑定过程。分享给大家供大家参考,具体如下: 在理解this 的绑定过程之前,首先要理解调用位置:调用位置就是函数在代码中被调用的位置(而不是声明的位置)。只有仔细分析...
主要介绍了javascript this详细介绍的相关资料,需要的朋友可以参考下
直到昨天翻了一下《JavaScript王者归来》这本书才算对this有一个深刻的理解。 大至归结一下: 1. 函数调用者与所有者 JavaScript 中函数(function) 存在调用者 与 所有者这两个概念,调用者是指调用函数的对象,通常...
2.JavaScript this 3.JavaScript 闭包 4.JavaScript 事件 5.javascript 跨域 6.javascript 命名空间 Oject-Oriented 1.JavaScript Expressive 2. Interfaces 3.Introduction 4. Inheritance 5.AOP Jquery ...
主要介绍了JavaScript this关键字指向常用情况解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
2.JavaScript this 3.JavaScript 闭包 4.JavaScript 事件 5.javascript 跨域 6.javascript 命名空间 Oject-Oriented 1.JavaScript Expressive 2. Interfaces 3.Introduction 4. Inheritance 5.AOP Jquery ...
JavaScriptthis绑定规则以及箭头函数相关知识,以便于讨论学习
主要介绍了JavaScript this指向相关原理及实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
js原生态函数中使用jQuery中的 $(this)无效的解决方法.docx
JavaScript this 关键字 面向对象语言中 this 表示当前对象的一个引用。 但在 JavaScript 中 this 不是固定不变的,它会随着执行环境的改变而改变。 在方法中,this 表示该方法所属的对象。 如果单独使用,this ...