Javascript 从方法/模块调用自执行函数

Javascript 从方法/模块调用自执行函数,javascript,methods,anonymous-function,Javascript,Methods,Anonymous Function,假设我有一个由私有和公共方法组成的函数,如下所示: (function () { var private_var = "hey"; function private_function () { // stuff } stuff = { public_var: "hey", public_function: function () { // this can be called from the

假设我有一个由私有和公共方法组成的函数,如下所示:

(function () {
    var private_var = "hey";
    function private_function () {
        // stuff
    }
    stuff = {
        public_var: "hey",
        public_function: function () {
            // this can be called from the outside with no prob.
        },
        do_this_now_and_later: (function dothis() {
            // i could call this from the namespace "dothis()"
            // but not the method name, stuff.do_this_now_and_later()
        })()
    }
})(window.load = window.load || {});
我想执行函数do_this_now_,渲染完成后再执行,但也要稍后执行


如果我正确编写了这个示例代码,应该可以通过名称空间dothis调用该函数,但是可以通过其方法调用该函数吗?

尝试在函数中返回dothis

(function () {
var private_var = "hey";
function private_function () {
    // stuff
}
stuff = {
    public_var: "hey",
    public_function: function () {
        // this can be called from the outside with no prob.
    },
    do_this_now_and_later: (function dothis(v) {
        alert(v);
        return dothis;
        // i could call this from the namespace "dothis()"
        // but not the method name, stuff.do_this_now_and_later()
    })('foo')
}

stuff.do_this_now_and_later('bar');
})(window.load = window.load || {});

只有当你回来做这件事;在这篇文章的结尾。。。