noConflict方法在库(accounting.js库)中如何工作?

时间:2019-05-06 20:04:19

标签: javascript undefined accounting.js

这是代码(具体来说是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吗?

0 个答案:

没有答案