【发布时间】:2011-11-20 14:54:44
【问题描述】:
这是一个简短的问题,因为我没有使用 Google 找到正确的答案。 好的,我有这个 Rails 项目,它有很多 JavaScript 文件(实际上是 CoffeeScript),看起来让球滚动的代码是这样的......
index.html.haml
:javascript
$(document).ready(function () {
window.Application.init()
});
这就是里面的全部内容,我不知道行: window.Application.init() 做什么?各位大神能解释一下吗?
我认为这非常重要,因为该项目主要是一堆咖啡脚本文件,几乎没有任何服务器端处理。
提前致谢!
编辑:(我找到了 Application 类的代码)
class Application
# Creates the map by using the geolocation center
# Returns a deferred promise with the bounds
setup = (position) ->
deferred = new $.Deferred()
Ext.setup
glossOnIcon: false
onReady: ->
Application.mapPanel = new MapPanel(position, deferred)
Application.loading = new Ext.LoadMask( Ext.getBody(), { msg: "Loading..." } )
deferred.promise()
# Handles the geolocation error.
@onFail = ->
Ext.setup
onReady: ->
new Ext.Panel
fullscreen: true,
dockedItems: [],
items: []
Ext.Msg.confirm "Position Unavailable",
"Can not confirm your location. Would you like to go to the instructions page?",
(button) ->
document.location = if button == "no" then "/posts" else "/instructions"
@init = ->
Geolocation.onStart = (position) ->
$.when(setup(position)).pipe(Post.latest).then (data) ->
Application.mapPanel.paintPosts data
Geolocation.onUserRejected = @onFail
Geolocation.init()
window.Application = Application
【问题讨论】:
-
如果没有看到“应用程序”对象的代码,就无法确定。它实际上可以是任何东西。
-
我已经在那里发布了请求的代码。我想一般地知道语法:window.Anything = 任何东西有什么作用? (我显然不明白 'Anything' 是一个 Coffeescript 类),但我想知道该语法最终完成了什么。谢谢先生。
标签: jquery ruby-on-rails haml coffeescript