When coffeescript is compiled, it is surrounded by immediate functions, but what should I do if I want to leave it out?
coffeescript
Add the -b
(--bare) option to the coffee command.
(However, the immediate function is to adjust the namespace so that variable names do not conflict with each other, so compiling in this way can cause unexpected problems.)
func.coffee:
square=(x)->x*x
cube=(x)->
square(x)*x
coffee-c func.coffee
output func.js:
//Generated by CoffeeScript 1.7.1
(function(){
varcube, square;
square=function(x){
return x*x;
};
cube=function(x){
return square(x)*x;
};
}).call(this);
coffee-b-c func.coffee
output func.js:
//Generated by CoffeeScript 1.7.1
varcube, square;
square=function(x){
return x*x;
};
cube=function(x){
return square(x)*x;
};
If you want to be able to see functions and variables from other file sources when you run them in your browser,
foo.coffee:
window.foo=(x)->
console.info"x=#{x}"
bar.js:
foo("test")
But I think you can refer to it
© 2024 OneMinuteCode. All rights reserved.