polymorphism - JavaScript: Use parent methods from child class? -


i'm trying use method parent class inside child class. in other languages, have use extends , methods parent can used in child, in javascript, seems different.

function svg() {     this.align = function(value) {         if(value === 'left') return 0;     } }  function graph() {     // want align text left     console.log('<text x="' + align('left') + '"></text>'); }  graph = new graph(); graph.prototype = new svg(); graph.prototype.align.call(); 

http://jsfiddle.net/cbmqg/9/

i understand code below doesn't 'extend' in other oop languages. take function/class property - can call it's methods directly. furthermore, haven't used javascript prototyping demo.

<script>     function svg() {         this.align = function( align ) {             if( align == 'left')                  return 'left';             else                 return 0;         }     }      function graph() {          this.svg = new svg();         // want align text left         this.alignleft = function( direction ) {             console.log('<text x="' + this.svg.align( direction ) + '"></text>');         }     }      graph = new graph();     graph.alignleft('left');  //console.log <text x="left"></text>  </script> 

fiddle: http://jsfiddle.net/cbmqg/11/


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -