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. IF条件控制

    条件控制 定义 Python 条件语句是通过一条或多条语句的执行结果(True 或者 False)来决定执行的代码块. 如下图所示 IF语句 if condition_1: statement_blo ...

  2. 提高CUI测试稳定性技术

    GUI自动化测试稳定性,最典型的表现形式就是,同样的测试用例在同样的环境上,时而测试通 过,时而测试失败. 这也是影响GUI测试健康发展的一个重要障碍,严重降低了GUI测试的可信性. 五种造成GUI测 ...

  3. 第三方模块:gulp模块

    一.Gulp的使用 1. 使用npm install  gulp  下载gulp库文件 2. 在项目根目录下简历gulpfile.js文件 3. 重构项目的文件夹架构src目录放置源代码文件,dist ...

  4. 执行npm publish 报错:403 Forbidden - PUT https://registry.npmjs.org/kunmomotest - you must verify your email before publishing a new package: https://www.npmjs.com/email-edit

    前言 执行npm publish 报错:403 Forbidden - PUT https://registry.npmjs.org/kunmomotest - you must verify you ...

  5. 华为云搭建windows+wordpress+xampp

    1.如何将本地文件上传至华为云ECS云服务器(Windows系统) 1.1 在本地电脑上,快捷键“WIN+R"打开“运行”中输入“mstsc”,点击确定 1.2  在“远程桌面连接”框点击“ ...

  6. linux(centeros)svn的安装

    SVN linux搭建svn服务器参考:http://www.cnblogs.com/chaichuan/p/3758173.htmlSubversion(SVN) 是一个开源的版本控制系統, 也就是 ...

  7. JS 页面跳转,参数的传递

    当我们通过location.replace()进行页面的跳转时,我们想进行参数的传递,当时学习的时候,以前在网上找过获取方法,已经忘记出处在哪里了.获取方法大概是这样的: 1.将参数通过拼接的方式拼接 ...

  8. Linux 下安装中文字体

    本文以安装黑体为例,简单演示如何在Linux下安装中文字体. 环境信息介绍 [root@thatsit ~]# cat /etc/redhat-release CentOS Linux release ...

  9. 2019长安大学ACM校赛网络同步赛 B Trial of Devil (递归)

    链接:https://ac.nowcoder.com/acm/contest/897/B来源:牛客网 Trial of Devil 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32 ...

  10. VS2017报错:未提供初始值设定项

    今天在使用VS2017写程序时,报错: 出错的代码如下: #include "pch.h" #include <iostream> #include <threa ...