Javascript-this
来源:互联网 发布:上高速官方版淘宝 编辑:程序博客网 时间:2024/06/05 10:43
this
this是Javascript语言的一个关键字。它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用,随着函数使用场合的不同,this的值会发生变化。但是有一个总的原则,那就是this指的是,调用函数的那个对象。
function test(){ this.x = 1; }
纯粹的函数调用
var x = 1; function test(){ this.x = 0; } test(); alert(x); //0
作为对象方法的调用
function test(){ alert(this.x); } var o = {}; o.x = 1; o.m = test; o.m(); // 1
作为构造函数调用
var x = 2; function test(){ this.x = 1; } var o = new test(); alert(x); //2
apply调用
var x = 0; function test(){ alert(this.x); } var o={}; o.x = 1; o.m = test; o.m.apply(); //0
阅读全文
0 0
- javascript this
- javascript this
- JavaScript---this
- JavaScript ???????? this ??
- javascript-this
- Javascript this
- JavaScript - This
- Javascript-this
- JavaScript-this
- 【javascript】javascript中的this
- 【javascript】javascript对象中的this
- 【javascript笔记】this in javascript
- JavaScript中的this指针
- javascript this详解
- javascript 中的"this"
- "this" of JavaScript
- javascript的this使用
- javascript this详解
- Java重写和重载
- HDU
- jzoj5043 【NOI2017模拟4.4】保持平衡 (可撤销贪心)
- 定时框架quartz的使用
- 5185 Equation
- Javascript-this
- Sophix移动热修复之如何使用(二)
- 大话数据结构 code 第八章 01静态查找_Search
- Java多线程
- 斯坦福大学公开课机器学习课程(Andrew Ng)八顺序最小优化算法
- 打不死的又如何能毁灭呢?尴尬的 Windows XP 是升级还是保留?
- 【连载】计算机组成原理 --- 概述
- 最短路简化版的两种解法
- mysql创建与回滚