用于调用 Namespace 函数的 Javascript Onready 函数

标签 javascript namespaces onready

我正在删除我的 Rails/views/show.html.erb 中使用的 Javascript 中的全局变量

我正在使用的 javascript 是

var App = {};
App.UserSnapShot = function () {
  var _body, _detailEl, _selectedLinkEl;

  var _init = function () {
    _body = $$("body")[0];

    $$(".user-link").each(function (el) {
      el.observe("mouseover", function (event) {
        _selectedLinkEl = el;
        _detailEl = event.element().next();
        _detailEl.show();
        _body.observe("mouseover", _bodyMouseOverFunction);
      });
    });
  };

  var _bodyMouseOverFunction = function (event) {
    if (event.element() != _selectedLinkEl && 
        event.element() != _detailEl && 
        !event.element().ancestors().include(_detailEl)) {
      _detailEl.hide();
      _body.stopObserving("mouseover", _bodyMouseOverFunction);
    }
  };

  return {
    init: function () {
      _init();
    }
  };
}();

我需要调用我的函数 App.UserSnapShot.init(); 通过相同的 onready 函数 .. ,以便让它工作..
如何在此处添加 onReady 函数。

请给一些建议

最佳答案

你的意思是?

App.onReady = function() {
    App.UserSnapShot.init();
};

document.observe("dom:loaded", App.onReady);

关于用于调用 Namespace 函数的 Javascript Onready 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4201859/

相关文章:

javascript - 将 DIV 排成一圈,并朝外旋转

javascript - 在 url 中获取具有正则表达式模式的搜索词

C++ — `algorithm` 库和命名空间 `std`

javascript - 检查 DOM 是否准备就绪是否过度?

javascript - jQuery:如何检测页面将在刷新时返回的偏移量?

javascript - 颜色根据列出的数字发生变化

javascript - cocos2d-js 不能立即绘制圆

python - 将单个 python 文件与 "extras"包一起打包

.net - 在 .net 中重命名命名空间