Solved

Using this to set a value in javascript

Posted on 2016-10-25
1
26 Views
Last Modified: 2016-11-01
HI,
In my js file i have the following code :
var data;
exports.setData = function(data) {
    this.data = data;
}

Now whenever i have to use the value of data have to type this.data

so when i am using this where is data created.. ?
And how do i set the value inside the variable data rather than using this ??

Thanks
0
Comment
Question by:Rohit Bajaj
1 Comment
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41859423
How this behaves depends on whether you are in strict mode or not.

This article describes how this is interpreted.

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/this
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now