quirkey/sammy — pull request #131 by GilesBradshaw (2012-03-07 00:52:09+00:00)
Title: all prototypes are now extended rather than being created from scratch

I've been writing some coffeeScript to inherit one of the classes in Sammy like this:

class DataLocationProxyTest extends Sammy.DataLocationProxy
setLocation : (newLocation) ->
super newLocation

With the way DataLocationProxy is written this doesn't work because the constructor is not inherited. To be inherited DataLocationProxy.prototype.constructor would have to be the DataLocationProxy function.

This is because the prototype is defined as a new object :

Sammy.DataLocationProxy.prototype = {
bind: function() {
var proxy = this;
this.app.$element().bind('setData', function(e, key, value) {
if (key == proxy.data_name) {
......

if the prototype is defined like this :
$.extend(Sammy.DataLocationProxy.prototype, {bind : function() {
var proxy = this;
.....
unbind : function() {
if (this.href_attribute) {

&c then it is possible to inherit

Is there any reason that the prototypes are defined as they are and would it be better to extend rather than redefine them so that classes can be inherited? I note in other places it uses $.extend which does not cause this problem.

The code in this pull request uses $.extend for the modification of all prototypes.