How do you make anonymous classes in Coffeescript?

I have a working coffee pot / skeleton that looks like this:

SidebarWidgets = ((() -> SidebarWidgets = { } class SidebarWidgetPrototype extends Backbone.View initialize: (options) -> @template = $(options.templateId).html() render: () -> $(@el).html(_.template(@template, @model.toJSON())) @el class SidebarWidgets.user extends SidebarWidgetPrototype class SidebarWidgets.shoppingcart extends SidebarWidgetPrototype class SidebarWidgets.messages extends SidebarWidgetPrototype SidebarWidgets )()) class Sidebar extends Backbone.View views: ['user', 'shoppingcart', 'messages'] initialize: (options) -> @subviews = { } _.each(@views,(v) => subviews[v] = news SidebarWidgets[v]( model: cxDatasets[v] id: 'sidebar-' + v templateId: '#sidebar-' + v + 'template' ) ) render: () -> $(@el).html() _.each(@views, (v) => $(@el).append(@subview(v).render()) ) 

The purpose of this idiom is to provide a list of database views, which will then include a sidebar view, providing the ability (but not the need) to override or improve one or more widget methods.

What annoys me is that for those views that don't need to be modified, they still need to explicitly specify the syntax of the Coffeescript class.

Is there a way to create an anonymous class with Coffeescript syntax? Can you say something like (following pseudocode):

 thisclass = extend BackboneView initialize: (options) -> 

If so, how?

+6
source share
1 answer
 thisclass = class extends BackboneView initialize: (options) -> 
+16
source

Source: https://habr.com/ru/post/887955/


All Articles