The native javascript:
var Person;
Person = Backbone.Model.extend({});
This code is working fine if I write in google chrome console var person = new Person;
my main.coffee
Person = Backbone.Model.extend({})
the generated main.js
// Generated by CoffeeScript 1.4.0
(function() {
var Person;
Person = Backbone.Model.extend({});
}).call(this);
If I write in google chrome console:
var person = new Person;
ReferenceError: Person is not defined
How can I create a instance from console with generated javascript instead native javascript?
CoffeeScript defaults to wrapping all code in a function to avoid polluting the global namespace. You can compile the code with the
-b/--bareflag to avoid this wrapper, or usewindow.Person = Backbone.Model.extend({})to make it global manually, which is the common way of doing what you want in CoffeeScript.