新手求助:为什么这里的Console.log返回undefined?

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

为什么这里显示undefined?而不是3?求解答

回复
阅读 5.6k
6 个回答
function d(){this.get=function(){return this.getName()}};
d.prototype.getName=function(){return 3;};
var d = new d();
console.log(d.get());//undefined
function d(){this.get=function(){return this.getNum()}};

你说呢

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

自己对比下

this.getnum改成this.getname

新手上路,请多包涵
function d(){
            this.get= function(){
                return this.getName()
            }
        };
        d.prototype.getName = function(){
            return 3;
        };
        var d = new d();
        console.log(d.get());  
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏