0

別のコンストラクターからプロパティにアクセスする方法を取得しようとしています。たとえば、App、Effects、Utils などのオブジェクトを分離し、プロパティとメソッドを相互に呼び出したいと考えています。それは可能ですか、それともこの方法は完全に間違っていますか?

var App = function() {

    this.someProperty = 'Lorem';
    this.init();
};

App.prototype = {

    init:function(){
        this.bindEvents();
    },

    bindEvents:function(){

        var self = this;

        $(window).on('resize', function(e) {
            e.preventDefault();
            this.windowWidth = $(window).width();
            // Is that Correct?
            Utils.prototype.resizeElement(this.windowWidth);
        });

    }

};


var Utils = function(){};


Utils.prototype = {

    resizeElement: function(windowW){
        console.log(windowW);   
    },

    someMethod:function(){

        // How can i access property written in App constructor?
        console.log(this.someProperty);
    }

};


var Effects = function(){
    this.init();
};


Effects.prototype = {

    hideElement:function(ele){
        $(ele).hide();
    }

};


var app = new App();
4

1 に答える 1