-
WEB2 - JavaScript - 리팩토링(refactoring)JavaScript/생활코딩 2018. 12. 24. 14:16
리팩토링(refactoring) - https://opentutorials.org/course/3085/18801
리팩토링은 코드를 더 용이하고 효율적인 코드로 수정하는 작업이다. (중복된 코드를 간결하게 작업하는 것도 포함)
아래 코드는 this를 사용한 예제이다.
<h1><a href="index.html">WEB</a></h1>
<input id="night_day" type="button" value="night" onclick="
var target = document.querySelector('body'); //중복되는 코드를 변수에 담았다.
if(this.value === 'night'){
target.style.backgroundColor = 'black';
target.style.color = 'white';
this.value = 'day';
} else {
target.style.backgroundColor = 'white';
target.style.color = 'black';
this.value = 'night';
}
">
<ol>
<li><a href="1.html">HTML</a></li>
<li><a href="2.html">CSS</a></li>
<li><a href="3.html">JavaScript</a></li>
</ol>
<h2>JavaScript</h2>
<p>
JavaScript (/ˈdʒɑːvəˌskrɪpt/[6]), often abbreviated as JS, is a high-level, dynamic, weakly typed, prototype-based, multi-paradigm, and interpreted programming language. Alongside HTML and CSS, JavaScript is one of the three core technologies of World Wide Web content production. It is used to make webpages interactive and provide online programs, including video games. The majority of websites employ it, and all modern web browsers support it without the need for plug-ins by means of a built-in JavaScript engine. Each of the many JavaScript engines represent a different implementation of JavaScript, all based on the ECMAScript specification, with some engines not supporting the spec fully, and with many engines supporting additional features beyond ECMA.
</p>
'JavaScript > 생활코딩' 카테고리의 다른 글
WEB2 - JavaScript - 반복문, 배열과 반복문 (0) 2018.12.26 WEB2 - JavaScript - 반복문 예고, 배열 (0) 2018.12.26 WEB2 - JavaScript - 조건문, 조건문의 활용 (0) 2018.12.24 WEB2 - JavaScript - 조건문 예고, 비교연산자와 Boolean 데이터 타입 (0) 2018.12.21 WEB2 - JavaScript - 프로그램, 프로그래밍, 프로그래머 (0) 2018.12.19 댓글