You are here:

Javascript/Doubts using this keyword in Javascript

Advertisement


Question
In my project, we are using this keyword in many places. but i dont have idea for this keyword. Please explain that how to understand this?

Answer
Hi Mohanraj,

Thanks for your question. When used inside of a function, the "this" JavaScript keyword refers to the object within which the function is executing. It can be a confusing topic, because a function can be defined in one context, and executed with another using the .call() or .apply() methods. And when you instantiate a constructor function, the "this" keyword refers to the instance object itself, regardless of where that constructor is executed.

This topic can be a bit challenging to understand without code examples. Here are two blog posts I've already written that discuss this topic:

1) Understanding Context in JavaScript Object Literals:

http://blog.kevinchisholm.com/javascript/context-object-literals/

2) What is the difference between an Object Literal and an Instance Object in JavaScript ?:

http://blog.kevinchisholm.com/javascript/difference-between-object-literal-and-i


I hope this was helpful. Please feel free to follow-up with me directly if there are any other questions you may  have about the "this" keyword in JavaScript. I can be reached at:

kevin@kevinchisholm.com

Best Wishes,

Kevin Chisholm

http://kevinchisholm.com/

http://blog.kevinchisholm.com/

Javascript

All Answers


Ask Experts

Volunteer


Kevin Chisholm

Expertise

I can answer questions about: JavaScript, Object-Oriented JavaScipt, JSON, AJAX, jQuery, HTML, CSS

Experience

I am a Front-End Web Developer living in New York City. I have provided services to titles such as Time.com, TimeForKids.com, SportIllustrated.com, coastalliving.com, People.com, TDAmeritrade.com, and Instyle.com. Being particularly passionate about Object-Oriented JavaScript as well as Web Standards, I spend a fair amount of time writing about / teaching Front-End Web Development techniques. In my free time I enjoy reading about advanced JavaScript, as well as Web Development trends and best practices. My Blog is: http://blog.kevinchisholm.com/ JavaScript-specific blog posts can be found here: http://blog.kevinchisholm.com/category/javascript/

Organizations
NYC Front-end Developers CSS3 / HTML5 The future of front end Front-End Engineers Javascript Syracuse University Alumni Network

Education/Credentials
Syracuse University - VPA - 1983 - 1987

Past/Present Clients
cookingchanneltv.com foodnetwork.com food.com hgtv.com diynetwork.com gactv.com frontdoor.com hgtvremodels.com travelchannel.com Time.com TimeForKids.com SportIllustrated.com coastalliving.com People.com TDAmeritrade.com ramirezco.com njsga.org soccercoliseum.com superdomesports.com afeenj.org

©2016 About.com. All rights reserved.