Solved

Using this to set a value in javascript

Posted on 2016-10-25
1
36 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 52

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
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…

912 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