Why does this forEach return undefined when using a return statement

前端 未结 4 1550
自闭症患者
自闭症患者 2020-12-04 01:50
Object.prototype.e = function() {
    [].forEach.call(this, function(e) {
        return e;
    });
}; 
var w = [1,2];

w.e(); // undefined

But thi

4条回答
  •  暖寄归人
    2020-12-04 02:17

    The function e() isn't returning anything; the inner anonymous function is returning its e value but that return value is being ignored by the caller (the caller being function e() (and can the multiple uses of 'e' get any more confusing?))

提交回复
热议问题