About Subclassing in Javascript
Labels:
Javascript,
subclassing
Let the superclass be:
function Person(sex){alert('I am Person')}
and subclasses:
function Man(){this.sex='M'}
function Woman(){this.sex='F'}
The following two subclassing approaches don't seem to make any difference:
Man.prototype = new Person
Woman.prototype = new Person()
m = new Man()
w = new Woman()
In both cases:
- The function Person will be executed
- The constructor of both m and w are Person
No comments:
Post a Comment