Skip to content

Instantly share code, notes, and snippets.

@chul-hyun
Last active September 13, 2018 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chul-hyun/7abdedcad16af03f1e85ec05ff81f6ea to your computer and use it in GitHub Desktop.
Save chul-hyun/7abdedcad16af03f1e85ec05ff81f6ea to your computer and use it in GitHub Desktop.
캡슐화. 은닉성, getter setter를 쓰는것을 지양해야 하는 이유
class ProceduralStopWatch {
public startTime;
public stopTime;
getElapsedTime = () => this.startMsTime - this.stopMsTime
}
// example
const stopWatch = new ProceduralStopWatch();
stopWatch.startTime = Date.now();
somthing();
stopWatch.stopTime = Date.now();
const elapsedTime = stopWatch.getElapsedTime();
console.log(`result: ${elapsedTime}`);
class ProceduralStopWatch {
public startTime;
public stopTime;
public startNanoTime;
public stopNanoTime;
getElapsedTime = () => this.startMsTime - this.stopMsTime
getElapsedNanoTime = () => this.startNanoTime - this.stopNanoTime
}
// example
const stopWatch = new ProceduralStopWatch();
stopWatch.startNanoTime = performance.now();
somthing();
stopWatch.stopNanoTime = performance.now();
const elapsedNanoTime = stopWatch.getElapsedNanoTime();
console.log(`result: ${elapsedNanoTime}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment