Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.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 firefox说'this.view'未定义,但在控制台中转储对象时定义明确_Javascript_Jquery_Prototype - Fatal编程技术网

Javascript firefox说'this.view'未定义,但在控制台中转储对象时定义明确

Javascript firefox说'this.view'未定义,但在控制台中转储对象时定义明确,javascript,jquery,prototype,Javascript,Jquery,Prototype,我读了一篇关于通过创建单例,然后覆盖其构造函数并始终返回第一个创建的实例来构建单例的文章。这很好,但是我的一个方法无法引用其属性: //fetch a view and render it with the supplied args, then perform a callback. jqMVC.prototype.render = function(template,args,callback){ twig({ href: this.view_path+templat

我读了一篇关于通过创建单例,然后覆盖其构造函数并始终返回第一个创建的实例来构建单例的文章。这很好,但是我的一个方法无法引用其属性:

//fetch a view and render it with the supplied args, then perform a callback.
jqMVC.prototype.render = function(template,args,callback){
    twig({
        href: this.view_path+template,
        load: function(template) { 
            var html = template.render(args);
            this.view.html(html).promise().done(function(){
                if(typeof callback === "function"){
                    callback();
                }
            });
        }
    });
};

正如您在图中所看到的,视图是明确定义的,如果程序员没有覆盖它,甚至还有一个默认值。视图是一个jquery对象。如何在我的方法中使用它?

问题在
小树枝
回调
中,此
可能不是指
jqMVC
对象

您可以使用一个闭包变量,如下所示

jqMVC.prototype.render = function (template, args, callback) {
    var self = this;
    twig({
        href: this.view_path + template,
        load: function (template) {
            var html = template.render(args);
            self.view.html(html).promise().done(function () {
                if (typeof callback === "function") {
                    callback();
                }
            });
        }
    });
};

问题出在
twig
回调
中,该
可能不是指
jqMVC
对象

您可以使用一个闭包变量,如下所示

jqMVC.prototype.render = function (template, args, callback) {
    var self = this;
    twig({
        href: this.view_path + template,
        load: function (template) {
            var html = template.render(args);
            self.view.html(html).promise().done(function () {
                if (typeof callback === "function") {
                    callback();
                }
            });
        }
    });
};

问题出在
twig
回调
中,该
可能不是指
jqMVC
对象

您可以使用一个闭包变量,如下所示

jqMVC.prototype.render = function (template, args, callback) {
    var self = this;
    twig({
        href: this.view_path + template,
        load: function (template) {
            var html = template.render(args);
            self.view.html(html).promise().done(function () {
                if (typeof callback === "function") {
                    callback();
                }
            });
        }
    });
};

问题出在
twig
回调
中,该
可能不是指
jqMVC
对象

您可以使用一个闭包变量,如下所示

jqMVC.prototype.render = function (template, args, callback) {
    var self = this;
    twig({
        href: this.view_path + template,
        load: function (template) {
            var html = template.render(args);
            self.view.html(html).promise().done(function () {
                if (typeof callback === "function") {
                    callback();
                }
            });
        }
    });
};

“覆盖它们的构造函数”。这听起来很可怕。你能展示一下你是如何构建你的单身汉的代码吗?是的,我会发布完整的代码,因为显然我太笨了,不懂javascript。在我看来,这种语言是疯狂的,“覆盖它们的构造函数”。这听起来很可怕。你能展示一下你是如何构建你的单身汉的代码吗?是的,我会发布完整的代码,因为显然我太笨了,不懂javascript。在我看来,这种语言是疯狂的,“覆盖它们的构造函数”。这听起来很可怕。你能展示一下你是如何构建你的单身汉的代码吗?是的,我会发布完整的代码,因为显然我太笨了,不懂javascript。在我看来,这种语言是疯狂的,“覆盖它们的构造函数”。这听起来很可怕。你能展示一下你是如何构建你的单身汉的代码吗?是的,我会发布完整的代码,因为显然我太笨了,不懂javascript。在我看来,这种语言是疯狂的。