call () 과 appy ()

3422 단어 call
따다
Call () 방법
콜 () 방법 은 고전적 인 대상 사칭 방법 과 가장 비슷 한 방법 이다.그것 의 첫 번 째 매개 변 수 는 this 의 대상 으로 사용 된다.다른 매개 변 수 는 함수 자체 에 직접 전달 된다.예 를 들 면:
   1:  function sayColor(sPrefix,sSuffix) {
   2:      alert(sPrefix + this.color + sSuffix);
   3:  };
   4:   
   5:  var obj = new Object();
   6:  obj.color = "blue";
   7:   
   8:  sayColor.call(obj, "The color is ", "a very nice color indeed.");

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
Apply () 방법
apply () 방법 은 두 개의 인자 가 있 습 니 다. this 의 대상 과 함수 에 전달 할 인자 의 배열 입 니 다.예 를 들 면:
   1:  function sayColor(sPrefix,sSuffix) {
   2:      alert(sPrefix + this.color + sSuffix);
   3:  };
   4:   
   5:  var obj = new Object();
   6:  obj.color = "blue";
   7:   
   8:  sayColor.apply(obj, new Array("The color is ", "a very nice color indeed."));

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

좋은 웹페이지 즐겨찾기