First introduce the associative array:
Execute the above code and display 1.
In JavaScript, methods and properties are treated as values.
<script> <br>var test={ <br>a:1, <br>b:"string", <br>c:false, <br>d:function show(){alert("OK"); <br>} <br>}; <br>var show=test.d; <br>show(); <br></script>
Execute the above code and it will show OK. First, an object test is defined, which has four attributes a, b, c, and d. The fourth one is a method, but it is still treated as a value
var show=test.d;
means assigning d to show. At this time, show is a function. Just show(); to execute this method.
Result display
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn