javascript对象问题

时间:2011-08-03 03:05:52

标签: javascript jquery

我正在尝试模仿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
}

在javascript或jquery中

1 个答案:

答案 0 :(得分:1)

使用Functioncall method

致电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
}