Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top