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() {
# (...)
}
Written by Adam Stankiewicz
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Coffeescript
Authors
iam4x
94.17K
ericdfields
63.02K
Related Tags
#coffeescript
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#