Javascript 从主干中的coffeescript返回对象
我想我错过了一些非常基本的东西。我只想从coffeescript中的函数中获取值。我正在为该值执行console.logJavascript 从主干中的coffeescript返回对象,javascript,function,backbone.js,coffeescript,Javascript,Function,Backbone.js,Coffeescript,我想我错过了一些非常基本的东西。我只想从coffeescript中的函数中获取值。我正在为该值执行console.log class App.Views.PlotModal extends Backbone.ModalView template: JST['plots/plot_modal'], render: -> console.log(@getSize.w); $(@el).html(@template(plot: @model)); this.sh
class App.Views.PlotModal extends Backbone.ModalView
template: JST['plots/plot_modal'],
render: ->
console.log(@getSize.w);
$(@el).html(@template(plot: @model));
this.showModal();
getSize: ->
cell_div = document.getElementById("bgr");
w : cell_div.offsetWidth * 3;
h : cell_div.offsetHeight * 2;
当我在firebug中转到控制台时,我一直没有定义。如果我只记录@getSize,我就可以恢复函数。如何在这里返回变量w和h
在主干视图中执行这种操作(我想动态调整iframe的大小)也是一个好主意吗 在CoffeeScript中,将变量
x
中的方法f
保留为一个简单函数:
x = @f
如果要调用函数,则必须提供参数:
x = @f 'pancakes'
或添加括号:
x = @f()
所以你想要这个:
console.log(@getSize().w)
至于在主干网做这种事情,当然,为什么不呢?主干网往往会将政策留给您。太好了,非常感谢!你能评论一下第二部分吗?这种功能属于主干视图吗?@Stpn:我想我在你第一次阅读后加上了“当然可以,为什么不可以?”。我看不出有什么理由不这样做,一个对话框
和其他任何东西一样都是一个视图,视图应该尽可能地照顾自己。