0

在我的构造函数中,我订阅了另一个类函数。如何从订阅中调用类方法 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 在这里:

/// <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();
});
    }

谢谢。书呆子

4

2 回答 2

0

尝试替换MemPortfolio.Portfolio.prototypeMemPortfolio.prototype.Portfolio

于 2013-03-05T19:01:53.927 回答
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();
    });
        }
于 2013-03-06T04:33:13.500 回答