이 코드는 어떤 기능을합니까? 특히 프로토 타입 부분을 의미합니다. 전달 된 체인 객체는 CSS 이름/값 쌍의 객체입니다. defaultFactory는 이름 값 쌍을 가진 객체를 반환한다고 생각합니다. 내가 모르는 것은 프로토 타입을 설정하는 것입니다.이 프로토 타입 코드는 무엇을합니까?
function addDefaultStyleToProtoChain(chain):Object {
// If there's a defaultFactory for this style sheet,
// then add the object it produces to the chain.
if (defaultFactory != null)
{
var originalChain:Object = chain;
// from here on...
defaultFactory.prototype = chain;
chain = new defaultFactory();
defaultFactory.prototype = null;
}
return chain;
}
이 플렉스 4.6 SDK 상황에 대한
의의 CSSStyleDeclaration 클래스의 addDefaultStyleToProtoChain 방법, 어떤 경우에 : 동일한 체인을 무엇
var o:Object = new defaultFactory();
trace(o) // {fontFamily:Arial, color:blue};
trace(chain) // {color:red, fontWeight:bold}
defaultFactory.prototype = chain;
chain = new defaultFactory();
trace(chain) // ???
?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ UPDATE ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~이 아래의 답변에 따라
것은 무슨이다 :
// create a function that returns an object
var myDynamicDefinition:Function = function() {
this.name = "initialvalue";
trace('this.name='+this.name); // returns this.name=initialvalue
}
var dynamicDefinitionInstance = new myDynamicDefinition(); // create an instance of myDynamicDefinition
trace(ObjectUtil.toString(dynamicDefinitionInstance));// returns name = "initialvalue"
// create a new definition and assign it to our dynamic definitions
var newDefinition = {color:"red", name:"newObjectValue"};
myDynamicDefinition.prototype = newDefinition;
// create a new instance with new definition
var dynamicDefinitionInstance2 = new myDynamicDefinition(); // create an instance of myDynamicDefinition
trace(ObjectUtil.toString(dynamicDefinitionInstance2)); // returns name = "initialvalue" color = "red"
// delete name property instance
delete dynamicDefinitionInstance2.name;
trace(ObjectUtil.toString(dynamicDefinitionInstance2)); // returns name = "newObjectValue" color = "red"
// set prototype to null
myDynamicDefinition.prototype = null;
// create a new instance
var dynamicDefinitionInstance3 = new myDynamicDefinition();
trace(ObjectUtil.toString(dynamicDefinitionInstance2)); // returns name = "newObjectValue" color = "red"
새 인스턴스가 생성 된 후에는 새 인스턴스의 속성 값이 변경되지 않습니다. 따라서 처음에는 아무런 차이가 없습니다. 이 속성이 삭제되면 프로토 타입 객체의 값이 FALLBACK으로 사용됩니다. 위의 예제 코드와 반환 값을 참조하십시오. 즉, 그 시점에서 앞으로 당신이 그 클래스의 인스턴스를 개체 대신 원래의 클래스의 새 버전을 얻을 수 있도록 기본적으로 프로토 타입을 설정
는
은 그래서 기존의 클래스에 속성과 메서드에 추가하거나 기존 클래스를 대체있어? 메서드가 이미 존재하면 새 속성을 병합하는 경우? 끝났습니까? –
나는 그것이 실제로는 아니지만 기존 클래스를 대체한다고 생각할 것이다. 그것은 기존 클래스를 정의하는 것을 대체하고, 그 클래스를 구현하는 객체가 의미하는 바를 대체합니다. 예, 기존 방법을 무시할 수 있습니다. 나는이 용어가 "과부하"라고 믿는다. – invertedSpear