gpt4 book ai didi

javascript - 将 Keen.io 与 CoffeeScript 一起使用不起作用?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:48:32 24 4
gpt4 key购买 nike

我正在尝试使用 Keen.io,我按如下方式将他们的 JS 转换为咖啡:

# Keen init
Keen = Keen or
configure: (e) ->
@_cf = e

addEvent: (e, t, n, i) ->
@_eq = @_eq or []
@_eq.push([e, t, n, i])

setGlobalProperties: (e) ->
@_gp = e

onChartsReady: (e) ->
@_ocrq = @_ocrq or []
@_ocrq.push(e)

(->
e = document.createElement("script")
e.type = "text/javascript"
e.async = not 0
e.src = ((if "https:" is document.location.protocol then "https://" else "http://")) + "dc8na2hxrj29i.cloudfront.net/code/keen-2.1.0-min.js"

t = document.getElementsByTagName("script")[0]
t.parentNode.insertBefore e, t
)()

Keen.configure myParams

Keen.addEvent "script_tag_init"

但看起来事件没有发生。给了什么?

最佳答案

是的,那就是问题所在。由于 CoffeeScript 的编译方式,Keen 对象在全局范围内不可见。

初始化后“导出”Keen 到窗口将起作用。

或者,您可以直接在窗口对象上初始化 Keen:

# Keen init
window.Keen =
configure: (e) ->
@_cf = e
...

注意:此方法不首先检查 Keen 是否已存在于页面上,这是一种极端情况下的性能优化,对于大多数应用程序而言不是必需的。换句话说应该没问题。

关于javascript - 将 Keen.io 与 CoffeeScript 一起使用不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20894011/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com