ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • WEB2 - JavaScript - 함수의 활용
    JavaScript/생활코딩 2018. 12. 27. 16:00



    함수의 활용 - https://opentutorials.org/course/3085/18883




    <h1><a href="index.html">WEB</a></h1>

      <input id="night_day" type="button" value="night" onclick="

        nightDayHandler(this);

      ">

      <input id="night_day" type="button" value="night" onclick="

        nightDayHandler(this);

      ">

      <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>


    nightDayHandler(self) 함수는 head에 위치하고 있으며 코드상에는 넣지 않았다.


    input태그에서 nightDayHandler()안에 this를 넣지 않으면 head에 위치한 함수가 실행될 때  그 안에서 사용되는 self는 전역객체를 가리키게 된다.

    그러므로 nightDayHandler(this)이렇게 설정함으로써 head에 위치한 함수가 실행되면 this는 input태그를 가리키기 때문에 정상적으로 동작한다.




    [동작과정]

    버튼을 클릭한다 -> input태그안의 nightDayHandler(this)가 실행된다. -> head에 위치한 함수가 실행된다. -> this는 head에 위치한 nightDayHandler(self)의 self로 들어간다.

    댓글

Designed by Tistory.