프레임 워크 건물에서 "확장 지점"을 수행 할 계획이며 기능을 추가 할 수 있지만 핵심 개체를 노출하지 않도록 확장에 "핵심"을 제공 할 수있는 방법을 찾고 있습니다.예기치 않은 닫힘 동작
(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?
'kit.core'는 참조 또는 포인터가 아닙니다. 로컬 변수'core'와 마찬가지로 값입니다. – Raynos
Raynos :'kit.core'가'core' 로컬 객체를 가리키고 있습니다. 개체를 수정하면 다른 개체도 변경됩니다. –
@KarolyHorvath'kit.core'의 ** 내용 **을 변경하면 "getCore()"함수가 변경 내용을 보게됩니다. 그러나,'kit.core'가 새로운 것을 참조하게 만들면, (OP가 발견되면) 관계가 깨집니다. – Pointy