Many times in JavaScript we have to reach deep into objects to access fields that could possibly not be there at all; for example let’s assume I have a JS object called options into which I’ve just read an entire JSON configuration file. Trying to access a field like options.application.cache.enable directly will potentially fail (e.g. when any of the intermediate levels is missing)… if (options.application.cache.enable) { // do stuff }
Continue readingTag: OOP
JS classes for the masses.
Following on an older post of mine, I decided to write a new article about an(other) implementation of OOP Classes in JavaScript. This is something that brings a lot of value from very few lines of code and I want to share it with everyone and see how it can be improved. First let’s see the code (you should check here for the latest version) and then I’ll try and
Continue readingA simple(r) approach for class-based OOP in JavaScript.
Like others before me, I found JavaScript’s prototype-based OOP support – while very powerful – quite cumbersome in some situations where I needed a certain structure or hierarchy of objects, situations in which one quickly comes to the conclusion that the best answer would be the concept of a Class. However, while I am well aware that the web is filled with various implementations of classical (i.e. class-based) object orientation
Continue reading