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; }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Ecma Script 문법 (2)지난 번에는 es6문법에서 비교적 개념 이해가 쉬우며, 코드 사용법에 대한 변화정도에 대해서 설명했었다. 이번에는 개인적으로 내가 es6문법을 공부할 때 가장 이해하기 어려웠던(지금도 정확하게 이해가 잘 되지 않는 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.