I am trying to create a square in JavaScript that will be inherited and overridden in some ways.
I am using the following structure:
function myClass () {this.myvar = null; This.someotherVar = {someFunction: function (A, B) {function1 (A, B); }}} // Some functions MyClass.prototype.functionA = function {}} MyClass.prototype.functionB = function () {functionC ();} // Some functions that will be overrided by MyClass.prototype.function1 = function ( ) {...} MyClass.prototype.functionC = function () {...} Now I have 2 problems:
-
functionC in functionB because it is defined later? -
How do I function 1 inside some functions correctly?
1 in functionC Can there be a problem using functionB because it is defined later? No you have to call it properly:
function () {this.functionC (); } // ^^^^^ otherwise the function will not be found.
Of course you also need to make sure that functionB is defined only once functionC . 2. How can I relate to function1 inside some functions correctly? A small problem is that there is no method of someFunction example, but for some other object To call still the correct function1 , you can store a reference in a variant for example: function myClass () {var self = this ; This.myvar = null; This.someotherVar = {someFunction: function (A, B) {self.function1 (a, b); }}; }
No comments:
Post a Comment