这是代码(具体来说是398到407):
https://github.com/openexchangerates/accounting.js/blob/master/accounting.js#L403
我不明白这种方法:
// Use accounting.noConflict to restore `accounting` back to its original value.
// Returns a reference to the library's `accounting` object;
// e.g. `var numbers = accounting.noConflict();`
lib.noConflict = (function(oldAccounting) {
return function() {
// Reset the value of the root's `accounting` variable:
root.accounting = oldAccounting;
// Delete the noConflict method:
lib.noConflict = undefined;
// Return reference to the library to re-assign it:
return lib;
};
})(root.accounting);
如果我执行var numbers = accounting.noConflict()
,它将把库放在numbers变量中。我不明白的是,为什么我numbers.noConflict
不确定。我知道lib.noConflict = undefined
将其设置为undefined
,但是由于下面的代码是lib
,所以它不是然后设置为return lib
吗?