Coder Social home page Coder Social logo

Comments (3)

aeksco avatar aeksco commented on July 2, 2024

You should be able access it with:

this.locale

Here's a functional example in CoffeeScript - different syntax, same principle:

App.Routers.Shop = Backbone.SubRoute.extend

  initialize: (options) ->
    @locale = options.locale

  routes:
    'books(/*subroute)'   : 'books'

  books: ->
    new App.Routers.Shop.Books("#{ @prefix }/books", { locale: @locale, createTrailingSlashRoutes: true })

from backbone.subroute.

newtonianb avatar newtonianb commented on July 2, 2024

Hi @aeksco, sorry I got carried away and forgot critical details that I'm both using marionette and Marionette.Subrouter https://github.com/pushchris/backbone.marionette.subrouter ... which both are supposed to be extensions but anyways, I understand why this works in your example and also see now why it doesn't work in mine (below) but I still would love to find a solution.

Backbone.Router > Marionne.AppRouter > Marionette.SubRouter

Marionette Router derived from Backbone Router and Marionette SubRouter derives from AppRouter but clearly there's a ton of more things happening.

In my case using appRoutes this from inside my callback just gives me back the actual controller passed to the router or in this case below API which is an object with keys representing the functions

API =
  myPath: ->
   # debugger  # how can I access options here
class MyApp.Router extends Marionette.SubRouter
 controller: API
 initialize: (options) ->
   { @myvar } = options
 appRoutes:
   "my-path" : "myPath"

I guess this is a Marionette question

from backbone.subroute.

aeksco avatar aeksco commented on July 2, 2024

Interesting - wasn't familiar with Marionette.Subrouter. Learning new things everyday :D

Superficially the issue you're experiencing appears to be a result of your method not being properly bound to the subrouter instance.

For example, you have:

  myCallback: function() {
    console.log(this.foo);
  }

Where you really need:

  myCallback: (function(_this) {
    return function() {
      console.log(_this.foo);
    };
  })(this)

If I'm not mistaken, the above is typically going to be used when the method you're defining is a callback that references instance fields in the parent object.

The distinction in CoffeeScript is terse and fails to clarify the underlying principles, though researching the nuances between thin arrows and fat arrows will shed some light on your dilemma, given of course that the rest of the code is functioning well.

    myCallback: ->
        console.log @foo

VS

    myBoundCallback: =>
      console.log @foo

Hope this helps - good luck!

from backbone.subroute.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.