`

this in javascript

阅读更多
在javascript中,this表示当前上下文,即调用者的引用。因此this的值并非由函数如何被声明而确定,而是由函数如何被调用而确定。

-----------------------------1月27日补充-------------------------------------

javascript里的this就是被调用对象的引用。形象的说,就是那"."之前的那个对象的引用。
javascript里的函数在调用的时候总是跟某个对象绑定在一起的。直接调用一个看似没有跟什么对象绑定的函数,实际上是跟“全局”对象绑定在一起了。在浏览器DOM里这个全局对象就是window。
当使用new运算符来构造新对象时,new之后跟着的那个构造器里的"this"指向的就是由new而构造出来的一个空的新对象。

-----------------------------2月9日补充-------------------------------------

如果调用Function.call()或者Function.apply()方法,则第一个参数就直接作为this。
分享到:
评论

相关推荐

    Functional.Programming.in.JavaScript.1784398225

    looking for the quantum leap towards mastering the JavaScript language, or just want to become a better programmer in general, then this book is ideal for you. It is aimed at programmers involved in ...

    JavaScript Functional Programming for JavaScript Developers (PDF, EPUB, MOBI)

    looking for the quantum leap toward mastering the JavaScript language, or just want to become a better programmer in general, then this book is ideal for you. This guide is aimed at programmers, ...

    This year in JavaScript 2018 in review and npm’s predictions for 2019

    在这个由Laurie Voss, co-founder and COO of npm, Inc. 所做的研究中,我们可以通过该文档了解到2018年JavaScript的回顾以及npm对未来2019年的JavaScript开发趋势的预测。从这项研究中,我们能够提取出一些关键知识...

    Functional.Programming.in.JavaScript.2016.6.pdf

    In complex web applications, the low-level details of your JavaScript code can obscure the workings of the system as a whole. As a coding style, functional programming (FP) promotes loosely coupled ...

    JavaScript: Moving to ES2015

    This course offers an expert's eye on the latest ES6 features and how these advanced tasks fit together in JavaScript as a whole Discover robust JavaScript implementations of classic and advanced ...

    javascript面向对象编程指南 2nd

    In depth discussion of data types, operators, and flow control statements in JavaScript In depth discussion of functions, function usage patterns, and variable scope Understand how prototypes work ...

    Functional Programming in JavaScript(PACKT,2015)

    The book first explores the core concepts of functional programming common to all functional languages, with examples of their use in JavaScript. It's followed by a comprehensive roundup of functional...

    JavaScript this keyword

    Study note on htis keyword in JavaScript

    Beginning JavaScript, 4th Edition

    This guide to JavaScript builds on the success of previous editions and introduces you to many new advances in JavaScript development. The reorganization of the chapters helps streamline your ...

    JavaScript in 10 Minutes

    ### JavaScript in 10 Minutes: Key Insights for Intermediate and Advanced Programmers #### Introduction "JavaScript in 10 Minutes" is a concise guide that aims to provide intermediate to advanced ...

    JavaScript.The.Definitive.Guide

    This Fifth Edition is completely revised and expanded to cover JavaScript as it is used in today's Web 2.0 applications. This book is both an example-driven programmer's guide and a keep-on-your-desk ...

    Packt.Object-Oriented.JavaScript.3rd.Edition

    oriented programming accessible and understandable to web developers Write better and more maintainable JavaScript code while exploring interactive examples that can be used in your own scripts Who ...

    JavaScript Patterns

    and other language-specific categories, the abstractions and code templates in this guide are ideal -- whether you're writing a client-side, server-side, or desktop application with JavaScript....

    Javascript类的继承,使用this.callParent调用超类方法

    console.log('I am in Grade ' + this.grade); }; ``` 这里,我们首先获取了`sayHello`方法在父类原型上的引用,然后通过`call`方法将其绑定到当前对象(`this`),确保上下文正确。这样,`Student`类的`sayHello`...

    Effective JavaScript: 68 Specific Ways to Harness the Power of JavaScript[EPUB版]

    No matter how long you’ve been writing JavaScript code, Effective JavaScript will help deepen your understanding of this powerful language, so you can build more predictable, reliable, and ...

    Professional JavaScript for Web Developers英文版

    This book provides a developer-level introduction along with more advanced and useful features of JavaScript. Coverage includes: JavaScript use with HTML to create dynamic webpages, language concepts ...

Global site tag (gtag.js) - Google Analytics