Javascript对象问题

javascript object problem

本文关键字:问题 对象 Javascript      更新时间:2023-09-26

我正在尝试模拟mongodb map-reduce。

function some_function(){
    ....
    call_some (some_object);
    ....
}
function call_some (some_object){
    // In here,
    // How could I use this keyword instead of some_object?
    // some_object.something => this.something
}

使用Functioncall方法调用call_some:

function some_function() {
    // ...
    call_some.call(some_object);
    // ...
}

或者,如果您不想以特殊的方式调用它,请尝试这样做:

function call_some(some_object) {
    if(this !== some_object) {
        return call_some.apply(some_object, arguments);
    }
    // do something interesting here
    // this === some_object
}