https://www.w3schools.com/js/js_this.asp

What is this?

The JavaScript this keyword refers to the object it belongs to.

It has different values depending on where it is used:

  • In a method, this refers to the owner object.
  • Alone, this refers to the global object.
  • In a function, this refers to the global object.
  • In a function, in strict mode, this is undefined.
  • In an event, this refers to the element that received the event.
  • Methods like call(), and apply() can refer this to any object.

this in a Method

In an object method, this refers to the "owner" of the method.

In the example on the top of this page, this refers to the person object.

The person object is the owner of the fullName method.

fullName : function() {
  return this.firstName + " " + this.lastName;
}
 
 
 
 

The JavaScript this Keyword的更多相关文章

  1. [Javascript] delete keyword

    delete keyword doesn't actually delete the value but just the reference. var me = { name: { first: & ...

  2. 专题:点滴Javascript

    JS#38: Javascript中递归造成的堆栈溢出及解决方案 JS#37: 使用console.time测试Javascript性能 JS#36: Javascript中判断两个日期相等 JS#3 ...

  3. JavaScript初学者必看“this”

    译者按: JavaScript的this和Java等面向对象语言中的this大不一样,bind().call()和apply()函数更是将this的灵活度进一步延伸. 原文: JavaScript: ...

  4. Understand JavaScript’s “this” With Clarity, and Master It

    The this keyword in JavaScript confuses new and seasoned JavaScript developers alike. This article a ...

  5. jQuery自定义组件——输入框设置默认提示文字

    if (window.jQuery || window.Zepto) { /** * 设置输入框提示信息 * @param options * @author rubekid */ var setIn ...

  6. U3D——Unity3D的脚本-script入门

     Unity3D的基本操作非常easy就能掌握了,接下来就是游戏系统的核心部分:脚本. 什么是Script(脚本)?简而言之,就是使用代码来运行一系列动作命令的特殊文本,它须要编译器来从新解读.U ...

  7. 用jQuery的ajax的功能实现输入自动提示的功能

    注意事项:要使用jQuery首先要把它的包引用进来( <script type="text/javascript" language="javascript&quo ...

  8. ajax冲刺03

    ---恢复内容开始--- 1.jq中ajax封装 简单的$.ajax方法使用示例:请关注 传参类型及数据 <!DOCTYPE html> <html lang="en&qu ...

  9. HTML5 LocalStorage Demo

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

随机推荐

  1. Luogu P5330 [SNOI2019]数论

    题目 如果\(P>Q\)的话我们先交换一下\(P,Q\). 我们先枚举所有满足第一个条件的数,对于\(x\equiv a_i(mod\ P)\),设\(x=a_i+kP(k\in[0,\lflo ...

  2. C语言中整形数组、字符数组、字符串的区别

    一. 第一 整型数组的存放,数组最后是不加'\0'的,字符串会自动加上,因此存放字符的时候数组的大小要比实际字符的多一个 第二 整型数组 每一个单元是4个字节的,字符串是一个一个字符存放的,每个字符占 ...

  3. oracle的隐藏的东东

    1: 在oracle中存在一种特殊的表单:dual 这是一张伪表,不是真正存在的 在日期的查询和触发器等多处用到 只展示系统当前时间: select sysdate from dual; 触发器:往往 ...

  4. 一般软件开发流程和BBS表设计

    项目开发流程 需求分析 架构师+产品经理+开发组组长 和客户公司谈需求之前 ,事先需要想一下这个项目要怎么做 里面的坑点提前想好比较简单的解决方案 在跟客户谈的时候有意识的引导客户朝你已经想好的方案上 ...

  5. jQuery进阶第三天(2019 10.12)

    一.原生JS快捷的尺寸(属性)(注意这些属性的结果 不带PX单位) clientWidth/clientHeight  =====> 获得元素content+padding的宽/高: offse ...

  6. webpack output的path publicPath

    path是用来定义入口文件保存的地址,而publicPath是定义非入口文件需要抽离保存的第三方文件的保存地址 vue-cli 中HtmlWebpackPlugin生成html,都会存在path路径上 ...

  7. empty()、isset()、is_null()的区别

    总结:1. 变量有二种状态: 已声明, 未声明2. 已声明的变量也有二种状态: 已赋值(初始化), 未赋值(未初始化)3. 变量可能会被赋值类型: null, 空值, 非空值 3.1: null值: ...

  8. Insomni'hack teaser 2019 - Misc - curlpipebash

    参考链接 https://ctftime.org/task/7454 题目 Welcome to Insomni'hack teaser 2019! Execute this Bash command ...

  9. shell字符串拼接

    name="Shell" url="http://c.biancheng.net/shell/" str1=$name$url #中间不能有空格 str2=&q ...

  10. python set 集合操作

    转自:https://www.cnblogs.com/alex3714/articles/5740985.html s = set([3,5,9,10]) #创建一个数值集合 t = set(&quo ...