フレームワークの構築で「拡張ポイント」を実行する予定です。拡張機能に「コア」を提供して、機能を追加できるが、任意に操作できるコアオブジェクトを公開しない方法を見つけています(iインターフェイスを提供する方が良いアイデアだと知っています)が、私がテストしている間(そして学習している間)、なぜこれが起こるのか疑問に思いました:
(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?