Why isPrototypeOf() returns false? Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara 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

Determinant of a matrix with 2 equal rows

RIP Packet Format

France's Public Holidays' Puzzle

How long can a nation maintain a technological edge over the rest of the world?

Can gravitational waves pass through a black hole?

What's called a person who works as someone who puts products on shelves in stores?

Mechanism of the formation of peracetic acid

Putting Ant-Man on house arrest

Will I be more secure with my own router behind my ISP's router?

Are these square matrices always diagonalisable?

Where to find documentation for `whois` command options?

What do you call an IPA symbol that lacks a name (e.g. ɲ)?

Protagonist's race is hidden - should I reveal it?

Raising a bilingual kid. When should we introduce the majority language?

What is a 'Key' in computer science?

Suing a Police Officer Instead of the Police Department

Why I cannot instantiate a class whose constructor is private in a friend class?

What happened to Viserion in Season 7?

Bright yellow or light yellow?

My admission is revoked after accepting the admission offer

What is a good proxy for government quality?

Does every subgroup of an abelian group have to be abelian?

When I export an AI 300x60 art board it saves with bigger dimensions

Why is arima in R one time step off?



Why isPrototypeOf() returns false?



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
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;








8















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












share|improve this question



















  • 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
    4 hours ago











  • Updated my question, sorry about that type

    – Gautam
    4 hours ago











  • try console.log(x.isPrototypeOf(new SubType)) for example of how it's used.

    – dandavis
    4 hours ago

















8















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












share|improve this question



















  • 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
    4 hours ago











  • Updated my question, sorry about that type

    – Gautam
    4 hours ago











  • try console.log(x.isPrototypeOf(new SubType)) for example of how it's used.

    – dandavis
    4 hours ago













8












8








8


2






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












share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 4 hours ago







Gautam

















asked 4 hours ago









GautamGautam

610413




610413







  • 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
    4 hours ago











  • Updated my question, sorry about that type

    – Gautam
    4 hours ago











  • try console.log(x.isPrototypeOf(new SubType)) for example of how it's used.

    – dandavis
    4 hours ago












  • 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
    4 hours ago











  • Updated my question, sorry about that type

    – Gautam
    4 hours ago











  • try console.log(x.isPrototypeOf(new SubType)) for example of how it's used.

    – dandavis
    4 hours 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
4 hours 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
4 hours ago













Updated my question, sorry about that type

– Gautam
4 hours ago





Updated my question, sorry about that type

– Gautam
4 hours ago













try console.log(x.isPrototypeOf(new SubType)) for example of how it's used.

– dandavis
4 hours ago





try console.log(x.isPrototypeOf(new SubType)) for example of how it's used.

– dandavis
4 hours ago












2 Answers
2






active

oldest

votes


















7














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








share|improve this answer






























    3














    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





    share|improve this answer








    New contributor




    David Klinge is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.




















      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
      );



      );













      draft saved

      draft discarded


















      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









      7














      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








      share|improve this answer



























        7














        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








        share|improve this answer

























          7












          7








          7







          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








          share|improve this answer













          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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 4 hours ago









          KaiidoKaiido

          46.4k468109




          46.4k468109























              3














              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





              share|improve this answer








              New contributor




              David Klinge is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.
























                3














                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





                share|improve this answer








                New contributor




                David Klinge is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






















                  3












                  3








                  3







                  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





                  share|improve this answer








                  New contributor




                  David Klinge is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.










                  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






                  share|improve this answer








                  New contributor




                  David Klinge is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer






                  New contributor




                  David Klinge is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered 3 hours ago









                  David KlingeDavid Klinge

                  864




                  864




                  New contributor




                  David Klinge is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  David Klinge is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  David Klinge is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.



























                      draft saved

                      draft discarded
















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      How to create a command for the “strange m” symbol in latex? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How do you make your own symbol when Detexify fails?Writing bold small caps with mathpazo packageplus-minus symbol with parenthesis around the minus signGreek character in Beamer document titleHow to create dashed right arrow over symbol?Currency symbol: Turkish LiraDouble prec as a single symbol?Plus Sign Too Big; How to Call adfbullet?Is there a TeX macro for three-legged pi?How do I get my integral-like symbol to align like the integral?How to selectively substitute a letter with another symbol representing the same letterHow do I generate a less than symbol and vertical bar that are the same height?

                      Българска екзархия Съдържание История | Български екзарси | Вижте също | Външни препратки | Литература | Бележки | НавигацияУстав за управлението на българската екзархия. Цариград, 1870Слово на Ловешкия митрополит Иларион при откриването на Българския народен събор в Цариград на 23. II. 1870 г.Българската правда и гръцката кривда. От С. М. (= Софийски Мелетий). Цариград, 1872Предстоятели на Българската екзархияПодмененият ВеликденИнформационна агенция „Фокус“Димитър Ризов. Българите в техните исторически, етнографически и политически граници (Атлас съдържащ 40 карти). Berlin, Königliche Hoflithographie, Hof-Buch- und -Steindruckerei Wilhelm Greve, 1917Report of the International Commission to Inquire into the Causes and Conduct of the Balkan Wars

                      Category:Tremithousa Media in category "Tremithousa"Navigation menuUpload media34° 49′ 02.7″ N, 32° 26′ 37.32″ EOpenStreetMapGoogle EarthProximityramaReasonatorScholiaStatisticsWikiShootMe