Why isPrototypeOf() returns false? Announcing the arrival of Valued Associate #679: Cesar...
When speaking, how do you change your mind mid-sentence?
Why I cannot instantiate a class whose constructor is private in a friend class?
Has a Nobel Peace laureate ever been accused of war crimes?
How to keep bees out of canned beverages?
Is there a verb for listening stealthily?
Why did Europeans not widely domesticate foxes?
Is there an efficient way for synchronising audio events real-time with LEDs using an MCU?
Protagonist's race is hidden - should I reveal it?
Raising a bilingual kid. When should we introduce the majority language?
Putting Ant-Man on house arrest
How to compute a Jacobian using polar coordinates?
A journey... into the MIND
Marquee sign letters
Did war bonds have better investment alternatives during WWII?
Is it appropriate to mention a relatable company blog post when you're asked about the company?
Married in secret, can marital status in passport be changed at a later date?
Writing a T-SQL stored procedure to receive 4 numbers and insert them into a table
Why do people think Winterfell crypts is the safest place for women, children & old people?
Does using the Inspiration rules for character defects encourage My Guy Syndrome?
What's parked in Mil Moscow helicopter plant?
Why is arima in R one time step off?
Co-worker works way more than he should
When I export an AI 300x60 art board it saves with bigger dimensions
What to do with someone that cheated their way though university and a PhD program?
Why isPrototypeOf() returns false?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30 pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Why is using “for…in” with array iteration a bad idea?Why does isNaN(“ ”) equal falseevent.preventDefault() vs. return falseWhat is JSONP, and why was it created?Why does Google prepend while(1); to their JSON responses?Why does ++[[]][+[]]+[+[]] return the string “10”?Is Safari on iOS 6 caching $.ajax results?How do I return the response from an asynchronous call?jQuery.inArray(), how to use it right?isPrototypeOf in Javascript
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have above constructors and SubType prototype pointing to an instance of SuperType. When I do x.isPrototypeOf(SubType.prototype)
it returns false
. I am confused as I have explicitly set x
as a prototype for SubType
. Can someone tell me why it's happening?
function SuperType(){}
function SubType(){}
x = new SuperType();
SubType.prototype = x;
SubType.prototype.constructor = SubType;
console.log(x.isPrototypeOf(SubType)) // returns false
console.log(SuperType.prototype.isPrototypeOf(SubType.prototype)) // returns true
javascript
add a comment |
I have above constructors and SubType prototype pointing to an instance of SuperType. When I do x.isPrototypeOf(SubType.prototype)
it returns false
. I am confused as I have explicitly set x
as a prototype for SubType
. Can someone tell me why it's happening?
function SuperType(){}
function SubType(){}
x = new SuperType();
SubType.prototype = x;
SubType.prototype.constructor = SubType;
console.log(x.isPrototypeOf(SubType)) // returns false
console.log(SuperType.prototype.isPrototypeOf(SubType.prototype)) // returns true
javascript
1
Not sure to get my head all clear here, butx === SubType.prototype
how do you expect it to be its own prototype?
– Kaiido
35 mins ago
Updated my question, sorry about that type
– Gautam
33 mins ago
tryconsole.log(x.isPrototypeOf(new SubType))
for example of how it's used.
– dandavis
27 mins ago
add a comment |
I have above constructors and SubType prototype pointing to an instance of SuperType. When I do x.isPrototypeOf(SubType.prototype)
it returns false
. I am confused as I have explicitly set x
as a prototype for SubType
. Can someone tell me why it's happening?
function SuperType(){}
function SubType(){}
x = new SuperType();
SubType.prototype = x;
SubType.prototype.constructor = SubType;
console.log(x.isPrototypeOf(SubType)) // returns false
console.log(SuperType.prototype.isPrototypeOf(SubType.prototype)) // returns true
javascript
I have above constructors and SubType prototype pointing to an instance of SuperType. When I do x.isPrototypeOf(SubType.prototype)
it returns false
. I am confused as I have explicitly set x
as a prototype for SubType
. Can someone tell me why it's happening?
function SuperType(){}
function SubType(){}
x = new SuperType();
SubType.prototype = x;
SubType.prototype.constructor = SubType;
console.log(x.isPrototypeOf(SubType)) // returns false
console.log(SuperType.prototype.isPrototypeOf(SubType.prototype)) // returns true
function SuperType(){}
function SubType(){}
x = new SuperType();
SubType.prototype = x;
SubType.prototype.constructor = SubType;
console.log(x.isPrototypeOf(SubType)) // returns false
console.log(SuperType.prototype.isPrototypeOf(SubType.prototype)) // returns true
function SuperType(){}
function SubType(){}
x = new SuperType();
SubType.prototype = x;
SubType.prototype.constructor = SubType;
console.log(x.isPrototypeOf(SubType)) // returns false
console.log(SuperType.prototype.isPrototypeOf(SubType.prototype)) // returns true
javascript
javascript
edited 33 mins ago
Gautam
asked 1 hour ago
GautamGautam
600413
600413
1
Not sure to get my head all clear here, butx === SubType.prototype
how do you expect it to be its own prototype?
– Kaiido
35 mins ago
Updated my question, sorry about that type
– Gautam
33 mins ago
tryconsole.log(x.isPrototypeOf(new SubType))
for example of how it's used.
– dandavis
27 mins ago
add a comment |
1
Not sure to get my head all clear here, butx === SubType.prototype
how do you expect it to be its own prototype?
– Kaiido
35 mins ago
Updated my question, sorry about that type
– Gautam
33 mins ago
tryconsole.log(x.isPrototypeOf(new SubType))
for example of how it's used.
– dandavis
27 mins ago
1
1
Not sure to get my head all clear here, but
x === SubType.prototype
how do you expect it to be its own prototype?– Kaiido
35 mins ago
Not sure to get my head all clear here, but
x === SubType.prototype
how do you expect it to be its own prototype?– Kaiido
35 mins ago
Updated my question, sorry about that type
– Gautam
33 mins ago
Updated my question, sorry about that type
– Gautam
33 mins ago
try
console.log(x.isPrototypeOf(new SubType))
for example of how it's used.– dandavis
27 mins ago
try
console.log(x.isPrototypeOf(new SubType))
for example of how it's used.– dandavis
27 mins ago
add a comment |
2 Answers
2
active
oldest
votes
SubType
is a function. What you probably want to check is if an instance of SubType would inherit from x
:
function SuperType(){}
function SubType(){}
x = new SuperType();
SubType.prototype = x;
SubType.prototype.constructor = SubType;
const instance = new SubType();
console.log(x.isPrototypeOf(instance)) // returns true
console.log(SuperType.prototype.isPrototypeOf(SubType.prototype)) // returns true
add a comment |
It helps to add properties to the objects to see what's happening. I fixed a little of your code. You can run this in the console:
function SuperType(foo){ this.foo = foo };
function SubType(bar){ this.bar = bar };
var x = new SubType("bar");
SuperType.prototype = x;
SuperType.prototype.constructor = SubType;
Now, you asked x.isPrototypeOf(SuperType)
and it returns false, because x
is not a property of the class SuperType
. But when you instantiate a SuperType
, x
is a property of that new object:
var y = new SuperType("foo");
console.log(x.isPrototypeOf(y)) // returns true
In your example that is true, SubType.prototype
is a prototype of SuperType.prototype
and returns true.
console.log(SubType.prototype.isPrototypeOf(SuperType.prototype)) // returns true
New contributor
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55821319%2fwhy-isprototypeof-returns-false%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
SubType
is a function. What you probably want to check is if an instance of SubType would inherit from x
:
function SuperType(){}
function SubType(){}
x = new SuperType();
SubType.prototype = x;
SubType.prototype.constructor = SubType;
const instance = new SubType();
console.log(x.isPrototypeOf(instance)) // returns true
console.log(SuperType.prototype.isPrototypeOf(SubType.prototype)) // returns true
add a comment |
SubType
is a function. What you probably want to check is if an instance of SubType would inherit from x
:
function SuperType(){}
function SubType(){}
x = new SuperType();
SubType.prototype = x;
SubType.prototype.constructor = SubType;
const instance = new SubType();
console.log(x.isPrototypeOf(instance)) // returns true
console.log(SuperType.prototype.isPrototypeOf(SubType.prototype)) // returns true
add a comment |
SubType
is a function. What you probably want to check is if an instance of SubType would inherit from x
:
function SuperType(){}
function SubType(){}
x = new SuperType();
SubType.prototype = x;
SubType.prototype.constructor = SubType;
const instance = new SubType();
console.log(x.isPrototypeOf(instance)) // returns true
console.log(SuperType.prototype.isPrototypeOf(SubType.prototype)) // returns true
SubType
is a function. What you probably want to check is if an instance of SubType would inherit from x
:
function SuperType(){}
function SubType(){}
x = new SuperType();
SubType.prototype = x;
SubType.prototype.constructor = SubType;
const instance = new SubType();
console.log(x.isPrototypeOf(instance)) // returns true
console.log(SuperType.prototype.isPrototypeOf(SubType.prototype)) // returns true
function SuperType(){}
function SubType(){}
x = new SuperType();
SubType.prototype = x;
SubType.prototype.constructor = SubType;
const instance = new SubType();
console.log(x.isPrototypeOf(instance)) // returns true
console.log(SuperType.prototype.isPrototypeOf(SubType.prototype)) // returns true
function SuperType(){}
function SubType(){}
x = new SuperType();
SubType.prototype = x;
SubType.prototype.constructor = SubType;
const instance = new SubType();
console.log(x.isPrototypeOf(instance)) // returns true
console.log(SuperType.prototype.isPrototypeOf(SubType.prototype)) // returns true
answered 27 mins ago
KaiidoKaiido
46.4k468109
46.4k468109
add a comment |
add a comment |
It helps to add properties to the objects to see what's happening. I fixed a little of your code. You can run this in the console:
function SuperType(foo){ this.foo = foo };
function SubType(bar){ this.bar = bar };
var x = new SubType("bar");
SuperType.prototype = x;
SuperType.prototype.constructor = SubType;
Now, you asked x.isPrototypeOf(SuperType)
and it returns false, because x
is not a property of the class SuperType
. But when you instantiate a SuperType
, x
is a property of that new object:
var y = new SuperType("foo");
console.log(x.isPrototypeOf(y)) // returns true
In your example that is true, SubType.prototype
is a prototype of SuperType.prototype
and returns true.
console.log(SubType.prototype.isPrototypeOf(SuperType.prototype)) // returns true
New contributor
add a comment |
It helps to add properties to the objects to see what's happening. I fixed a little of your code. You can run this in the console:
function SuperType(foo){ this.foo = foo };
function SubType(bar){ this.bar = bar };
var x = new SubType("bar");
SuperType.prototype = x;
SuperType.prototype.constructor = SubType;
Now, you asked x.isPrototypeOf(SuperType)
and it returns false, because x
is not a property of the class SuperType
. But when you instantiate a SuperType
, x
is a property of that new object:
var y = new SuperType("foo");
console.log(x.isPrototypeOf(y)) // returns true
In your example that is true, SubType.prototype
is a prototype of SuperType.prototype
and returns true.
console.log(SubType.prototype.isPrototypeOf(SuperType.prototype)) // returns true
New contributor
add a comment |
It helps to add properties to the objects to see what's happening. I fixed a little of your code. You can run this in the console:
function SuperType(foo){ this.foo = foo };
function SubType(bar){ this.bar = bar };
var x = new SubType("bar");
SuperType.prototype = x;
SuperType.prototype.constructor = SubType;
Now, you asked x.isPrototypeOf(SuperType)
and it returns false, because x
is not a property of the class SuperType
. But when you instantiate a SuperType
, x
is a property of that new object:
var y = new SuperType("foo");
console.log(x.isPrototypeOf(y)) // returns true
In your example that is true, SubType.prototype
is a prototype of SuperType.prototype
and returns true.
console.log(SubType.prototype.isPrototypeOf(SuperType.prototype)) // returns true
New contributor
It helps to add properties to the objects to see what's happening. I fixed a little of your code. You can run this in the console:
function SuperType(foo){ this.foo = foo };
function SubType(bar){ this.bar = bar };
var x = new SubType("bar");
SuperType.prototype = x;
SuperType.prototype.constructor = SubType;
Now, you asked x.isPrototypeOf(SuperType)
and it returns false, because x
is not a property of the class SuperType
. But when you instantiate a SuperType
, x
is a property of that new object:
var y = new SuperType("foo");
console.log(x.isPrototypeOf(y)) // returns true
In your example that is true, SubType.prototype
is a prototype of SuperType.prototype
and returns true.
console.log(SubType.prototype.isPrototypeOf(SuperType.prototype)) // returns true
New contributor
New contributor
answered 13 mins ago
David KlingeDavid Klinge
564
564
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55821319%2fwhy-isprototypeof-returns-false%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Not sure to get my head all clear here, but
x === SubType.prototype
how do you expect it to be its own prototype?– Kaiido
35 mins ago
Updated my question, sorry about that type
– Gautam
33 mins ago
try
console.log(x.isPrototypeOf(new SubType))
for example of how it's used.– dandavis
27 mins ago