Solved

Using this to set a value in javascript

Posted on 2016-10-25
1
51 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 56

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get CSS styled menu to maintain the open selected menu? 13 44
Coding for the first time 9 62
Jquery driving me nuts... 14 27
web page freezes after ajax post 7 43
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
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)

761 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