Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何全局公开和触发onready函数?_Javascript_Jquery - Fatal编程技术网

Javascript 如何全局公开和触发onready函数?

Javascript 如何全局公开和触发onready函数?,javascript,jquery,Javascript,Jquery,我将如何公开下面的两个函数以供全局访问函数WithInReady()和无柄物品() 在主题的范围内我可以触发以下功能: theme.handleSomething(); theme.functionWithinOnReady(); 假设我需要从第三个脚本(/全局)触发函数,我将如何以最好的方式实现这一点 (function($) { "use strict"; var theme = { onReady : function(){ f

我将如何公开下面的两个函数以供全局访问<代码>函数WithInReady()
无柄物品()

主题的范围内
我可以触发以下功能:

theme.handleSomething();
theme.functionWithinOnReady();
假设我需要从第三个脚本(/全局)触发函数,我将如何以最好的方式实现这一点

(function($) {
    "use strict";

    var theme = {

        onReady : function(){
            functionWithinOnReady = function() {
                //want to access this globally
            }
        },
        handleSomething: function() {
            //want to access this globally
        },
        onLoad : function() { },
        onResize : function() { }
    };


    $(document).ready( theme.onReady );
    $(window).load( theme.onLoad );
    $(window).resize( theme.onResize );

})(jQuery);

您可以将
主题
附加到窗口(全局)或jQuery

(function($) {
    "use strict";

    $.theme = {

        onReady : function(){
            functionWithinOnReady = function() {
                //want to access this globally
            }
        },
        handleSomething: function() {
            //want to access this globally
        },
        onLoad : function() { },
        onResize : function() { }
    };


    $(document).ready( $.theme.onReady );
    $(window).load( $.theme.onLoad );
    $(window).resize( $.theme.onResize );

})(jQuery);

现在,您可以在任何地方访问
$.theme
,如果要在jQuery集合上使用它,您可以使用
$.fn.theme
来原型化它。

window.theme={
。这会公开主题中的所有函数吗?因为我只想公开主题中的部分函数,所以您无法选择对象的哪些属性被公开,要么是整个对象,要么什么都没有。如果您想要特定的属性,请使用另一个对象引用
中所需的属性e
您是否有后一种方法的示例,或者我可以在哪里查阅该方法的一些示例?