1

Im using spinejs, coffeescript and asp.net mvc. Heres the code for spine controller class:

class Schedules extends Spine.Controller
    constructor: -> super alert "Created"

    events:
        "click": "click"

    click: ->
        alert("Was clicked")

In a asp.net mvc view I have all js included and the following code to init controller:

$(document).ready(function () {
     var sched = new Schedules({
         el: $("#myId")
     });  
});

But I see the following error: Uncaught ReferenceError: Schedules is not defined.

UPDATE: Now I it doesn`t do anything and no error is provided. I cant see my alert message. But it should show alert message after controller creation. In controller file:

window.SchedulesApp = {}
class SchedulesApp.Schedules extends Spine.Controller
//futher controller code

In the asp.net mvc View I have the following:

<script type="text/javascript">
            $(document).ready(function () {
                var controller = new SchedulesApp.Schedules({});
Yaroslav Yakovlev
  • 6,303
  • 6
  • 39
  • 59

1 Answers1

2

You should consider using namespaces:

window.SchedulesApp = {}

class SchedulesApp.Schedules extends Spine.Controller
    constructor: ->
        super
        alert "Created"

    events:
        "click": "click"

    click: ->
        alert("Was clicked")

EDIT

So, you have another problem and that is how you call super which is causing everything afterwards to be wrapped into a parameter to super.

I have fixed it with the CS output with jsFiddle and edited the CS in this answer.

Hope this helps!

Brian Genisio
  • 47,787
  • 16
  • 124
  • 167
  • Brian, I used your way to define namespace and I do not get any errors. But alert that is in controller constructor was not executed. Actually nothing is executed and I can`t call methods of controller if I define them. – Yaroslav Yakovlev Oct 11 '11 at 17:23
  • 1
    @YaroslavYakovlev can you create a jsFiddle to demonstrate your problem? – Brian Genisio Oct 11 '11 at 18:24
  • here it is http://jsfiddle.net/dDaej/ I tried to call controller.doStuff(and method was not defined). If reove this, no alerts still called on controller instantiation. The js I included was generated from coffeescript. – Yaroslav Yakovlev Oct 11 '11 at 19:27
  • 2
    @YaroslavYakovlev Ha! Take a look at the javascript in your fiddle. You have a problem with the way you are calling super and it is passing everything else in as a parameter to super... not good! :) I edited my response and gave you a jsFiddle that works. – Brian Genisio Oct 11 '11 at 20:15
  • Brian, thanks a lot! Just started to learn both coffeescript and spine. Thanks for helping with this. – Yaroslav Yakovlev Oct 11 '11 at 20:16