call, apply, bind는 함수의 실행 컨텍스트(this)를 지정하는데 유용한 메소드이다. this란 함수가 실행된 환경을 나타내는 것으로 보통은 함수가 실행되는 시점에 결정되며 이를 this가 함수에 바인딩된다고 한다. 여기서 바인딩 되는 this를 지정할 수 있게 해주는 것이 call, apply 이고, 바인딩되는 시점을 실행 시점으로부터 독립시켜주는 것이 bind 이다. call, apply 의 경우 호출 즉시 this가 바인딩되고 함수가 실행된다. 차이점은 파라미터가 나열형(call)이냐 배열(apply)이냐 정도이다. this를 지정한다는 것은 아무 값이나 지정할 수 있다는 의미는 아니고, 다음과 같이 생성자 체이닝으로 this를 통해 다른 메소드의 프로퍼티를 가져오는 효과를 얻을 수 있..
1. getter, setter 활용 const myObj = { this.someProperty = someValue; get someProperty() { return this.someProperty } set someProperty(newValue) { this.someProperty = newValue; alert("someProperty is changed!"); } }; 2. defineProperty 활용 defineProperty 메소드는 세 번째 파라미터로 descriptor를 제공하는데, 여기에서도 getter, setter를 설정할 수 있다. const myObj = { someProperty: someValue, }; Object.defineProperty(myObj, "somePr..
코드를 먼저 보면 다음과 같다. http.get을 통해 리모트 경로의 파일을 요청하고 응답으로 반환되는 Readable한 객체의 pipe 메소드를 통해 csv-parser를 실행시켜 주면된다. 참고로 readStream과 writeStream이 존재할 때 pipe는 다음과 동일하게 변경할 수 있다. const readStream = fs.createReadStream("some file"); // response const writeStream = fs.createWriteStream("another file"); readStream.on("data", (chunk) => { writeStream.write(chunk); }); // can be ==> readStream.pipe(writeStream)..
- Total