Add Caching to the Model Base Class

InstructorBrett Cassette

Share this video with your friends

Send Tweet

In the previous lessons we created a base class and looked at a caching mechanism for our models. In this lesson we will expand on that concept by test driving the addition of caching to our model base class, as well as some initial core functionality. This is advanced subject matter, and will require study of the code as well as watching the video.

Kevin
~ 10 years ago

I'm having a hard time following the definition of the privateVariable, particularly how it's setting up accessors.

The use of val variable throughout the function confuses me; I'm confused why value isn't used for get and set instead. The get seems like it'll throw undefined if it wasn't for the if statement at the end of the function (if (value !== undefined) object[name] = value;)

The existence of that particular if statement actually also confuses me because it seems like it should be a conditional statement inside of get instead of being outside the function.

For additional educational purposes, why wouldn't a data property attribute definition wouldn't work?

Within the privateVariable function, the following code snippet probably would work seemingly:

Object.defineProperty(object, name, {
  enumerable: true,
  configurable: false,
  value: value,
  writable: true
}

// value could also take a function that can return value after conditional statements, like checking if it's undefined to perhaps throw an exception or something...
Grégory
~ 9 years ago

The videos "full resource" do not open here. Codec? All others are normal.

Grégory
~ 9 years ago

Sorry, my download manager converted the extension .zip for mp4

valery
~ 9 years ago

Hi Guys,

First of all, thank you for your hard work. Could you help me, I can't download source code for this and other lessons from this playlist. When I click "available for download" link the browser starts downloading of related video instead of source code.

Thanks.