Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Some opinions:

function Woman(){
 Human.call(this);
}
Woman.prototype = new Human();

Don't use new for prototype Don't use new for prototype (even when it doesn't matter here as long as Human is empty, but the Huma.call(this) suggests otherwise). Check http://stackoverflow.com/q/10898786/1048572 https://stackoverflow.com/q/10898786/1048572

// Woman subClass
function Man(){

Apparently not.

 var _foo = 10;

It's a local-scoped ("private") variable anyway, you don't need to prefix it with an underscore. Notice that it is only accessible from functions declared within the constructor, of which you don't have any.

 return Human.call(this);

No reason to return anything here. It might even be wrong it Human did return an object.

Man.prototype.getInfo = function(method, url){
 [...]
}

This doesn't seem to have anything to do with instances of Man, so I wonder why it is a method? But that's probably just the design of your test case.

console.log('man private variable _foo: ' + (man._foo));

Not sure what you did expect, but yes, since _foo has been a variable and not a property of the object so this is undefined.

document.body.onclick = function(){ 
 [...]

...is missing a closing brace.

var randNr = Math.floor((Math.random()*1000)+1);
womans[randNr].talk();

No. That randNr will be in the range 1-1000 (both inclusive), while your array indices are 0-999. With a small chance, this will throw an exception. Remove the +1.

console.log('Random Woman: ' + randNr);

...and add it here if you want that output one-based.

Man.prototype.getInfo();

That confirms what I said above - you don't use an instance for that method. You should hardly ever call methods on the prototype object - man.getInfo() would be better. But if you really intended this to be a static function, you might write Man.getInfo = function() {...}; and then call Man.getInfo();.

Some opinions:

function Woman(){
 Human.call(this);
}
Woman.prototype = new Human();

Don't use new for prototype (even when it doesn't matter here as long as Human is empty, but the Huma.call(this) suggests otherwise). Check http://stackoverflow.com/q/10898786/1048572

// Woman subClass
function Man(){

Apparently not.

 var _foo = 10;

It's a local-scoped ("private") variable anyway, you don't need to prefix it with an underscore. Notice that it is only accessible from functions declared within the constructor, of which you don't have any.

 return Human.call(this);

No reason to return anything here. It might even be wrong it Human did return an object.

Man.prototype.getInfo = function(method, url){
 [...]
}

This doesn't seem to have anything to do with instances of Man, so I wonder why it is a method? But that's probably just the design of your test case.

console.log('man private variable _foo: ' + (man._foo));

Not sure what you did expect, but yes, since _foo has been a variable and not a property of the object so this is undefined.

document.body.onclick = function(){ 
 [...]

...is missing a closing brace.

var randNr = Math.floor((Math.random()*1000)+1);
womans[randNr].talk();

No. That randNr will be in the range 1-1000 (both inclusive), while your array indices are 0-999. With a small chance, this will throw an exception. Remove the +1.

console.log('Random Woman: ' + randNr);

...and add it here if you want that output one-based.

Man.prototype.getInfo();

That confirms what I said above - you don't use an instance for that method. You should hardly ever call methods on the prototype object - man.getInfo() would be better. But if you really intended this to be a static function, you might write Man.getInfo = function() {...}; and then call Man.getInfo();.

Some opinions:

function Woman(){
 Human.call(this);
}
Woman.prototype = new Human();

Don't use new for prototype (even when it doesn't matter here as long as Human is empty, but the Huma.call(this) suggests otherwise). Check https://stackoverflow.com/q/10898786/1048572

// Woman subClass
function Man(){

Apparently not.

 var _foo = 10;

It's a local-scoped ("private") variable anyway, you don't need to prefix it with an underscore. Notice that it is only accessible from functions declared within the constructor, of which you don't have any.

 return Human.call(this);

No reason to return anything here. It might even be wrong it Human did return an object.

Man.prototype.getInfo = function(method, url){
 [...]
}

This doesn't seem to have anything to do with instances of Man, so I wonder why it is a method? But that's probably just the design of your test case.

console.log('man private variable _foo: ' + (man._foo));

Not sure what you did expect, but yes, since _foo has been a variable and not a property of the object so this is undefined.

document.body.onclick = function(){ 
 [...]

...is missing a closing brace.

var randNr = Math.floor((Math.random()*1000)+1);
womans[randNr].talk();

No. That randNr will be in the range 1-1000 (both inclusive), while your array indices are 0-999. With a small chance, this will throw an exception. Remove the +1.

console.log('Random Woman: ' + randNr);

...and add it here if you want that output one-based.

Man.prototype.getInfo();

That confirms what I said above - you don't use an instance for that method. You should hardly ever call methods on the prototype object - man.getInfo() would be better. But if you really intended this to be a static function, you might write Man.getInfo = function() {...}; and then call Man.getInfo();.

Post Migrated Here from stackoverflow.com (revisions)
Source Link
Bergi
  • 1.8k
  • 9
  • 16

Some opinions:

function Woman(){
 Human.call(this);
}
Woman.prototype = new Human();

Don't use new for prototype (even when it doesn't matter here as long as Human is empty, but the Huma.call(this) suggests otherwise). Check http://stackoverflow.com/q/10898786/1048572

// Woman subClass
function Man(){

Apparently not.

 var _foo = 10;

It's a local-scoped ("private") variable anyway, you don't need to prefix it with an underscore. Notice that it is only accessible from functions declared within the constructor, of which you don't have any.

 return Human.call(this);

No reason to return anything here. It might even be wrong it Human did return an object.

Man.prototype.getInfo = function(method, url){
 [...]
}

This doesn't seem to have anything to do with instances of Man, so I wonder why it is a method? But that's probably just the design of your test case.

console.log('man private variable _foo: ' + (man._foo));

Not sure what you did expect, but yes, since _foo has been a variable and not a property of the object so this is undefined.

document.body.onclick = function(){ 
 [...]

...is missing a closing brace.

var randNr = Math.floor((Math.random()*1000)+1);
womans[randNr].talk();

No. That randNr will be in the range 1-1000 (both inclusive), while your array indices are 0-999. With a small chance, this will throw an exception. Remove the +1.

console.log('Random Woman: ' + randNr);

...and add it here if you want that output one-based.

Man.prototype.getInfo();

That confirms what I said above - you don't use an instance for that method. You should hardly ever call methods on the prototype object - man.getInfo() would be better. But if you really intended this to be a static function, you might write Man.getInfo = function() {...}; and then call Man.getInfo();.

default

AltStyle によって変換されたページ (->オリジナル) /