Question

In this line of code of an Backbone app:

window.App ?= {}

what does ?= mean? Is is something like initialization of a Backbone app with empty defaults?

I'm new to Backbone/CoffeeScript and I read that an empty app (in CoffeeScript) would look like:

window.MyApp =
  Models: {}
  Collections: {}
  Views: {}
  Routers: {}
  initialize: -> 
    #do stuff

So is the first a shorthand for the second?

Was it helpful?

Solution

It is the existential operator in CoffeeScript and would be (almost) equivalent to this JS

window.App = window.App || {};

It ensures that your App namespace is defined.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top