javascript中this指向问题的综合
来源:互联网 发布:维斯布鲁克数据库 编辑:程序博客网 时间:2024/05/23 21:19
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>this-调用函数的方式有关</title>
<script type="text/javascript">
/*
var a = 1;
function test(){
var a = 2;
console.log(this);
console.log(this.a);
}
test();
var obj = {a:3};
obj.test=test; //引用数据类型
obj.test(); //3
var obj2 = {a:5};
obj2.test=obj.test; //引用数据类型
obj2.test(); //5
//test obj.test obj2.test 指向同一个函数 调用的方式不同 this不同
var test2 = obj2.test;
//加括号为调用方法,不加为方法的引用
test2(); //window
//
*/
var obj = {
name:"terry",
sayName:function(){
alert(this.name);
}
}
//var callMethod=function(method){method();}
function callMethod(method){
method(); //method中的this 指向window window中找不到name
//obj.sayName();
}
callMethod(obj.sayName);
/*obj.sayName();
var test = obj.sayName();
test();
*/
</script>
</head>
<body>
</body>
</html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>this-调用函数的方式有关</title>
<script type="text/javascript">
/*
var a = 1;
function test(){
var a = 2;
console.log(this);
console.log(this.a);
}
test();
var obj = {a:3};
obj.test=test; //引用数据类型
obj.test(); //3
var obj2 = {a:5};
obj2.test=obj.test; //引用数据类型
obj2.test(); //5
//test obj.test obj2.test 指向同一个函数 调用的方式不同 this不同
var test2 = obj2.test;
//加括号为调用方法,不加为方法的引用
test2(); //window
//
*/
var obj = {
name:"terry",
sayName:function(){
alert(this.name);
}
}
//var callMethod=function(method){method();}
function callMethod(method){
method(); //method中的this 指向window window中找不到name
//obj.sayName();
}
callMethod(obj.sayName);
/*obj.sayName();
var test = obj.sayName();
test();
*/
</script>
</head>
<body>
</body>
</html>
0 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中setTimeout的作用域以及this指向问题
- javascript中this的指向问题(一)
- javascript中this 的指向问题(二)
- 细说JavaScript中this指向问题
- 第3.1.1章 WEB系统最佳实践 js控件之slimScroll的使用
- 一天一条Linux指令-uname
- 读《白说》有感
- VBA SQL连接
- go服务端----使用gin框架搭建简易服务
- javascript中this指向问题的综合
- 论文笔记-Augmented Lagrange Multiplier Method for Recovery of Low-Rank Matrices
- Android 连接指定的wifi
- 1149计算题
- 让生命孤独的怒放——《晚安 北京》读后感
- 【C语言】写一个宏将一个数字的奇数位和偶数位交换
- Activity的生命周期和启动模式
- R对象属性与槽
- usb各个描述符的解释说明