我计划在正在构建的框架中做“扩展点”,我正在寻找一种方法如何为扩展提供“核心”,以便它可以添加功能但不暴露可以任意操作的核心对象(我知道提供接口是更好的主意)但是,当我在测试(以及学习)时,我想知道为什么会发生这种情况:
(function() {
var core = {'bar': 'foo'}
function getCore() {return core;}
window.kit = {
core: core,
getCore: getCore
}
}());
//initial check
console.log(kit.core)
console.log(kit.getCore());
//change the bar
kit.core.bar = 'baz';
//we will both see 'baz'
console.log(kit.core)
console.log(kit.getCore());
//null the core
kit.core = null;
//this time...
console.log(kit.core) //core is null on this one
console.log(kit.getCore()); //why is the core still there on this one?