Private Data on Constructors: A Closure Example

preview_player
Показать описание
At times you need data on an JavaScript object that remains private; meaning you can't change except through some interface/function you have provided. In this video we show a pattern for accomplishing this.

Videos on Closure:

Videos on Prototypes:

Videos on Constructors:

For a complete list of all our tutorials:

Take the Learn Modern JavaScript: Getting Started or the Learn Modern JavaScript: Advanced Topics courses at a huge discount:
Рекомендации по теме
Комментарии
Автор

I love your tutorials very much, these tutorials really touch the delicate yet essential part of javascript. Thank you very much.

rotrose
Автор

This is great! Now, is it possible to control the access to variables in Greeting's prototype?
There is a way to do it. Creating an IIFE directly outside of Greeting's declaration that contains getter and setter functions to Greeting's prototype.
Example: Greeting.prototype.getName = function () {
However, is there a way of doing this but have all of this code in the body of Greeting instead?

mattsmith
Автор

nice tutorial, please make javascript problem solving video, that's are very useful to be expert as like me the beginner, plz plz..

smmosfequrrahaman