Search code examples
javascriptbackbone.jsgoogle-chrome-devtoolsbackbone-views

Call Backbone view method from inside google chrome console


I'd like to have access to my Backbone View object from inside the console. So for example lets say I have

mySlider = new SliderView( el: $('.slider')[0] )

and that SliderView has a goTo(idx) method. How can I do this inside the console:

mySlider.goTo(1)

Solution

  • You need to add the view to the global scope by attaching it to the window object:

    window.mySlider = new SliderView( el: $('.slider')[0] );
    

    Now you can access it in the Chrome console:

    mySlider.goTo(1);