tr7ctq
Last Updated: February 25, 2016
·
1.066K
· sheerun
Photo on 08.01.2013 at 04.15

Extend cleanly any JS class

Coffeescript's class syntax is compatible with JavaScript's prototype inheritance solutions. For example you can extend Google Maps classes using concise and DRY:

class ns.CustomMarker extends google.maps.OverlayView
  constructor: (@map, @param) ->
    this.setMap(map)

  draw: -> # (...)

Instead of doing it the official, dirty way ;)

ns.CustomOverlay = function(map, param) {
  this.param = param;
  this.map = map;
  this.setMap(map);
}

ns.CustomOverlay.prototype = new google.maps.OverlayView();

ns.CustomOverlay.prototype.draw = function() {
  # (...)
}