4 ms·
I think this problem can be easily solved by encapsulating access/creation methods of posts objects in a object say postStore where posts variable is private pr
by mun2mun 14y ago
I think this problem can be easily solved by encapsulating access/creation methods of posts objects in a object say postStore where posts variable is private property and the object have savePost(slug) and getPost(slug) methods where access/creation methods are defined by yourself. If posts object is that much mission critical than it should not be exposed to outer world.
- kansface 14y agoInstead of writing code around the problem, its better to just use a safe reference (ie, use Underscore's has method which will call Object.prototype.hasOwnProperty). This way code stays both simple and safe.