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。在我看来,这种语言是疯狂的。