Javascript&jquery.this keywords

Source: Internet
Author: User

this keyword

The This keyword is typically used inside a function or inside an object.

The location of a function or method declaration affects the meaning of the This keyword.

Typically, this points to the object that the current function is manipulating.

<!DOCTYPE html>

< html lang = "en" > < head >      < meta charset = "UTF-8" >      < title >this关键字</ title > </ head > < body > < script >      window.onload=function (ev) {          // 调用对象          this.person.eat();      }       var person={};//字面量创建对象       // 设置字面量对象属性      person.name=‘huangshiren‘;      person.age=58;      person.appetite=3;      person.eat=function(){          var value=this.name+‘的饭量是‘+this.appetite;          document.write(value+‘< br >‘);          document.write(‘正在吃饭‘);      } </ script > </ body > </ html >Test Questions

1, how to determine the point of this keyword?

For:

    • Fun () is a global function, while the declared fun receives a simple function in obj, and does not call (Obj.say () is called function), at this time the fun is a function (function () {alert (THIS.STR);} ), then when the fun () Call function, this point is the window
    • Who is calling the function, then this is pointing to WHO

2. Do you want to use this keyword?

Answer: No

Javascript&jquery.this keywords

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.