Tuesday, 17 September 2013

Read properties and call methods from another object Javascript Prototype Pattern

Read properties and call methods from another object Javascript Prototype
Pattern

Im trying to get how can I access properties from another constructor. I
want to separate objects like App, Effects, Utils for example and call
properties and methods from one to another. Is that possible, or is this
way completely wrong way?
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();

No comments:

Post a Comment