Does Basic CoffeeScript not fire events at startup?

I'm having real problems writing a simple Backbone.js application using CoffeeScript and Zepto.js

This is the simplest kind of Backbone, but events do not fire. Am I also not mistaken in the console? Where am I mistaken?

#Main view
class AppView extends Backbone.View

  constructor: ->    
    @el = $("#books")    
    @template = _.template("<div>New Item <a href='' id='addNew'> add new item</a></div>")

  events: {
      "click" : "createNew"
  }

  render: =>
    @el.html(@template())

  createNew : ->
    console.log "new"


#Onload
$(document).ready ->
   view = new AppView
   view.render()

I followed the only example that I can find in CoffeeScript and Backbone together https://github.com/bnolan/Backbone-Mobile/blob/master/application.coffee

However, if I add super to my view code above, I get an undefined error, its code does not work.

+3
source share
2 answers

Backbone.View constructor, , , super. Bad.

Backbone.View initialize. . Backbone.View#constructor initialize.

#Main view
class AppView extends Backbone.View

  initialize: ->    
    @el = $("#books")    
    @template = _.template(
      "<div>New Item <a href='' id='addNew'> add new item</a></div>"
    )
+5

( ), , @el. :

@el: $("#content")

.

+2

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


All Articles