Tag Archives: JavaScript

Strategy pattern: Transcoder example (JavaScript flavour)

This example is based on the declaration “Strategy pattern: Transcoder example“ Sources JS Bin About the code Based on as commented with generic example: TrancoderStrategy Declaration by prototype property The default behavior throw an exception in order to force subclasses to implement thesse methods

Concretes Strategies Declaration by prototype property  and Object.create()

Inheritance approaches in JavaScript

We are going to develop the following case: Two classes: Base: parent class with the same structure. State: color (string type, private scope). Behavior: sayColor, returning color. Child: subclass from Base with: State: name (string type, private scope). Behavior: sayName, returning name. Instanciating of child object. If we use a “classical” OOP language like Java:… Read More »

Defining Classes and Objects in JavaScript

We’d like to create one new object “Car” in JavaScript with the same features: property / state: color method: showColor One way to create your own objects in JavaScript instancing from JavaScript Object:

But so that we have a trouble: we can’t reuse the same structure (states & methods) to generate new oCar objects How… Read More »