![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript: lexical scoping issue using new keyword constructor while adding inner function?
To fix this, use the concept of this keyword. User another variable to hold the value of object, to use that inside the inner function.
Example
Following is the code −
function Employee() { this.technologyName = "JavaScript"; var currentTechnologyName = this; function workingTechnology() { console.log("I am working with " + currentTechnologyName.technologyName + " Technology"); } workingTechnology(); } var currentTechnology = new Employee();
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo216.js.
The output is as follows −
PS C:\Users\Amit\JavaScript-code> node demo216.js I am working with JavaScript Technology
Advertisements