가능한가요? 그렇다면 어떻게 될까요?자체 생성 기능?
원래 기능
호출 foo는()
새로운 기능
:var foo = function() { console.log("Original Function"); this = function() { console.log("New Function"); } }; console.log("Calling foo()"); foo();
원하는 출력 (작동하는 나는 방법을 찾을 수가 없었다)
사전에 질문에 답변하려면 예. 이것을하는 방법. 나는 단지 var bar = new foo();
과 같은 것을 할 수 있고 여분의 기능없이 시간에 의존하는 속성을 foo()
할당하면 궁금합니다.
편집 : Charmanders의 질문에 응답하고, 약간 덜 단순화, 더 실용적인 응용 프로그램
var node = function(parent)
{
this = function()
{
for (i in this)
{
// perform actions (which will occasionally include calling i()
}
}
if (parent !== null)
{
this.parent = parent;
// code to determine children
this.somechild = new node(this);
this.someotherchild = new node(this);
}
};
var ancestor = new node(new node(null));
귀하의 사례는 귀하의 질문과 매우 관련이있는 것으로 보입니다. 성취하고자하는 바를 정확히 기재하십시오. 이유는 무엇입니까? –