Created
January 10, 2014 10:25
-
-
Save dtomasi/c5316c76ea9fa0c68286 to your computer and use it in GitHub Desktop.
Revisions
-
Dominik Tomasi created this gist
Jan 10, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,109 @@ /** * Vorlage für Klassenaufbau mit Vererbung in Javascript * @constructor */ /** * Define Class ParentClass * @constructor */ function ParentClass() { /** * Define Properties * @type {string} */ this.ExampleProperty = 'Hello' } /** * Define A Funktion for Class ParentClass * @param sayWhat */ ParentClass.prototype.sayHello = function(sayWhat){ console.log('Method sayHello() from ParentClass'); console.log(sayWhat); }; /** * Define a ChildClass * @constructor */ function ChildClass() { /** * Define Child Property * @type {string} */ this.ExampleProperty2 = 'Hello Number 2'; /** * Overwrite Parent Property * @type {string} */ this.ExampleProperty = 'say '; /** * Extend Parent Property * @type {string} */ this.ExampleProperty = ChildClass.parent.ExampleProperty + 'Hello World'; } /** * Define Parent for ChildClass for Inherit Methods and Properties * @type {ParentClass} */ ChildClass.prototype = new ParentClass(); /** * Set Parent For Calling Parent Methods form overwritten Methods in Child Class * @type {ParentClass} */ ChildClass.parent = new ParentClass(); /** * Reset Pointer to right Constructor * Because Constructor-Pointer is set to ParentClass by Inherit * @type {ChildClass} */ ChildClass.prototype.constructor = ChildClass; /** * Overwrite Parent Method * @param sayWhat */ ChildClass.prototype.sayHello = function(sayWhat) { console.log('called Child Method'); ChildClass.parent.sayHello(sayWhat); }; /** * Create a Instance of ParentClass * @type {ParentClass} */ var parent = new ParentClass(); // Call a Function parent.sayHello('Hello'); console.log('ExampleProperty of ParentClass'); console.log(parent.ExampleProperty); /** * Create a Instance of ChildClass * @type {ChildClass} */ var child = new ChildClass(); // Call the same Function with other Params child.sayHello('Say What?'); console.log('ExampleProperty of ChildClass'); console.log(child.ExampleProperty); console.log('ExampleProperty2 of ChildClass'); console.log(child.ExampleProperty2);