在我的构造函数中,我订阅了另一个类函数。如何在订阅中调用类方法show。
var MemPortfolio = MemPortfolio || {};
MemPortfolio.Portfolio = function (contentid, thumbclass, featuredid) {
this.thumbClass = thumbclass;
this.featuredId = "#" + featuredid;
var that = this;
//subscribe to menutile click
$.subscribe("/menutile/click/portfolio", function (tilename) {
that.Show();
});
};
MemPortfolio.Portfolio.prototype.Show = function () {
alert("show");
}
在我的文件准备中: /// ///
$(document).ready(function () {
//check exists?
var tilemenu = new MemTileMenu.Menu("menu", "menuitem", "contentarea");
var portfolio = new MemPortfolio.Portfolio("contentarea", "thumb", "");
});
我得到了这个 -
/// <reference path="jquery-1.7.1.js" />
/// <reference path="jquery.ba-tinypubsub.js" />
var MemPortfolio = MemPortfolio || {};
MemPortfolio.Portfolio = function (contentid, thumbclass, featuredid) {
this.thumbClass = thumbclass;
this.featuredId = "#" + featuredid;
};
MemPortfolio.Portfolio.prototype = {
show: function () {
alert("show");
},
subscribe: function () {
var that = this;
$.subscribe("/menutile/click/portfolio", function (tilename) {
that.show();
});
}
Doc.Ready here:
/// <reference path="tilemenu.js" />
/// <reference path="portfolio.js" />
$(document).ready(function () {
//check exists?
var tilemenu = new MemTileMenu.Menu("menu", "menuitem", "contentarea");
var portfolio = new MemPortfolio.Portfolio("contentarea", "thumb", "");
portfolio.subscribe();
});
}
感谢。 NerdPerson
答案 0 :(得分:0)
尝试按MemPortfolio.Portfolio.prototype
MemPortfolio.prototype.Portfolio
答案 1 :(得分:0)
这很有效。
/// <reference path="jquery-1.7.1.js" />
/// <reference path="jquery.ba-tinypubsub.js" />
var MemPortfolio = MemPortfolio || {};
MemPortfolio.Portfolio = function (contentid, thumbclass, featuredid) {
this.thumbClass = thumbclass;
this.featuredId = "#" + featuredid;
};
MemPortfolio.Portfolio.prototype = {
show: function () {
alert("show");
},
subscribe: function () {
var that = this;
$.subscribe("/menutile/click/portfolio", function (tilename) {
that.show();
});
}
Doc.Ready here:
/// <reference path="tilemenu.js" />
/// <reference path="portfolio.js" />
$(document).ready(function () {
//check exists?
var tilemenu = new MemTileMenu.Menu("menu", "menuitem", "contentarea");
var portfolio = new MemPortfolio.Portfolio("contentarea", "thumb", "");
portfolio.subscribe();
});
}