是'这个'总是为功能定义? [英] is 'this' always defined for functions?

查看:67
本文介绍了是'这个'总是为功能定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://www.frostjedi.com/terra /scripts/demo/this.html


''this''被定义为,据我所知,对于事件处理程序,但为什么是
$ b它定义了$ b,这里?


这里是代码:


<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Strict // EN"

" http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

< html xmlns =" http://www.w3.org/1999/xhtml" XML:朗= QUOT;恩" >

< head>

< title> this< / title>

< / head>


< body>

< script type =" text / javascript">

(function(){

if(this){

alert(test exists);

} else {

alert(" test doesn' 不存在);

}

})();

< / script>

< ; / body>

< / html>

http://www.frostjedi.com/terra/scripts/demo/this.html

''this'' is defined, as I understand it, for event handlers, but why is
it defined, here?

Here''s the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<title>this</title>
</head>

<body>
<script type="text/javascript">
(function() {
if (this) {
alert("test exists");
} else {
alert("test doesn''t exist");
}
})();
</script>
</body>
</html>

推荐答案

yawnmoth< te ******* @ yahoo.comwrites:
yawnmoth <te*******@yahoo.comwrites:
http://www.frostjedi.com/terra/scripts/demo/this.html


''这个''已定义,据我了解,对于事件处理程序,但为什么它定义了

,这里?


这里是代码:


<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Strict // EN"

" http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

< html xmlns =" http ://www.w3.org/1999/xhtml" XML:朗= QUOT;恩" >

< head>

< title> this< / title>

< / head>


< body>

< script type =" text / javascript">

(function(){

if(this){

alert(test exists);

} else {

alert(" test doesn' 不存在);

}

})();

< / script>

< ; / body>

< / html>
http://www.frostjedi.com/terra/scripts/demo/this.html

''this'' is defined, as I understand it, for event handlers, but why is
it defined, here?

Here''s the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<title>this</title>
</head>

<body>
<script type="text/javascript">
(function() {
if (this) {
alert("test exists");
} else {
alert("test doesn''t exist");
}
})();
</script>
</body>
</html>



" this"表示方法调用的对象。简而言之,无论什么时候它都没有引用更具体的东西,它指的是全局的

对象(窗口对象,忽略了一些细节)。


在特定对象的方法调用中,this指的是

调用的对象(在这方面,DOM事件就像方法调用一样)。


函数bla(){

//用this做一些事情

}


bla()//对全局对象采取行动

var foo = {bar:bla}


foo.bla()//对foo对象采取行动


var zee = {};


foo.bla.call(z)//作用于zee对象

-

Joost Diepenmaat |博客: http://joost.zeekat.nl/ |工作: http://zeekat.nl/

"this" means the object of a method call. in short, whenever it
doens''t refer to anything more specific, it refers to the global
object (the "window" object, ignoring some details).

In method calls on a specific object, "this" refers to the object of
the call (and DOM events act like method calls in that respect).

function bla() {
// do something with "this"
}

bla() // act on the global object

var foo = { bar: bla }

foo.bla() // act on the foo object

var zee = {};

foo.bla.call(z) // act on the zee object
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

Joost Diepenmaat< jo *** @ zeekat.nlwrites:
Joost Diepenmaat <jo***@zeekat.nlwrites:

var zee = {};


foo.bla.call(z)//对zee对象执行操作
var zee = {};

foo.bla.call(z) // act on the zee object



应该是


foo。 bla.call(zee)//作用于zee对象


-

Joost Diepenmaat |博客: http://joost.zeekat.nl/ |工作: http://zeekat.nl/

that should have been

foo.bla.call(zee) // act on the zee object

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

8月26日下午4:20 *,Joost Diepenmaat< jo ... @ zeekat.nlwrote:
On Aug 26, 4:20*pm, Joost Diepenmaat <jo...@zeekat.nlwrote:

Joost Diepenmaat< jo .. 。@ zeekat.nlwrites:
Joost Diepenmaat <jo...@zeekat.nlwrites:

var zee = {};
var zee = {};


foo.bla.call(z)//对zee对象执行操作
foo.bla.call(z) // act on the zee object



应该是


foo.bla.call(zee)//对zee对象执行操作


that should have been

foo.bla.call(zee) // act on the zee object



谢谢 - 我很感激!

Thanks - I appreciate it!


这篇关于是'这个'总是为功能定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆