search

Home  >  Q&A  >  body text

javascript - Newbie asking for help: Why does Console.log here return undefined?

function d(){this.get=function(){this.getNum()}};
d.prototype.getName=function(){return 3;} ;
var d = new d();
console.log(d.get());//undefined

Why is undefined shown here? Instead of 3? Please answer

滿天的星座滿天的星座2882 days ago631

reply all(6)I'll reply

  • 怪我咯

    怪我咯2017-05-19 10:48:15

    function d(){this.get=function(){return this.getName()}};
    d.prototype.getName=function(){return 3;};
    var d = new d();
    console.log(d.get());//undefined

    reply
    0
  • 迷茫

    迷茫2017-05-19 10:48:15

    function d(){this.get=function(){return this.getNum()}};

    What do you say

    reply
    0
  • 某草草

    某草草2017-05-19 10:48:15

    function d(){this.get=function(){return this.getName();}};
    d.prototype.getName=function(){return 3;};
    var d = new d();
    console.log(d.get());

    Compare for yourself

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-19 10:48:15

    num name

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-19 10:48:15

    this.getnum is changed to this.getname

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:48:15

    function d(){
                this.get= function(){
                    return this.getName()
                }
            };
            d.prototype.getName = function(){
                return 3;
            };
            var d = new d();
            console.log(d.get());  

    reply
    0
  • Cancelreply