Day 8, dancer party sprint

We started a new sprint, with the purpose of using jQuery, CSS and HTML5. The assignment is fairly straight forward. There is a Dancer class that we need to extend to a subclass and the subclass are supposed to do all kinds of random stuff.

The biggest challenge is to convert the Dancer class and its subclass from the original functional form to the industry standard pseudo classical form. It takes a very long time for us to figure it out.  The syntax is not very intuitive. For example, we had Dancer class and BlueDancer subclass.

To establish the class-subclass relationship, we need to do:


BlueDancer.prototype = new Dancer(); // or BlueDancer.prototype = Object.create(Dancer.prototype);

BlueDancer.prototype.constructor = BlueDancer;

Inside the BlueDancer class definition, we need to add one line:


Dancer.call(this, arguments);

A couple of lessons:

– When a class creates its instance, the instance’s constructor property is automatically pointed back to the class.

– As soon as a function is declared, its prototype property and its prototype.constructor property come to existence. This is before any call to this function has been made.

– Mixin. They seems to be a cool way to modify objects efficiently. Mixin is more like a graph, while subclassing is more like a tree. When the constructors are mostly empty, they can just use Mixins.

– The difference between Mixin and subclassing is that Mixin works on existing objects and subclassing are creating new objects.

– We talked about whether ‘this’ would be part of the _.each()’s interface. The conclusion is that if the understanding of ‘this’ is required to use the function correctly, then ‘this’ is part of the interface.

– We also learned about pseudo classical, prototypal and functional

Advertisements
Standard