`
shameant
  • 浏览: 58740 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

this in javascript

    博客分类:
  • Ajax
阅读更多
 <script>
 function Foo(i, j){
 var i=i;
 var j=j;
 var a=3;
 alert(i);
 alert(this.i);
 }   
 var foo = new Foo(1,2);   
  </script>
 

 

The result is "1" and "undefined",so we can conclude that the  the "var i"  is not a property belong to Object  foo. It is a variable can be used in this function(notice:treat it as a function) ,but is not a property the class(I conside it as a java class).

 

 

<script>
 function Foo(i, j){
 var i=i;
 var j=j;
 var a=3;
 alert(i);
 alert(this.i);
 }   
 var foo = new Foo(1,2);   
  </script>

 

 In this way ,we declare a property named "i" of class Foo. and we can use  the property of Object foo:

<script>
alert(foo.i);
</script>
 

 

分享到:
评论

相关推荐

    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