prototype 예제
<button onclick="homzzang()">클릭</button> <p id="demo"></p> <script> Number.prototype.half = function() { return this.valueOf() / 2; }; function homzzang() { var n = 30; document.getElementById("demo").innerHTML = n.half(); } </script> 결과보기
<button onclick="homzzang()">클릭</button>
<p id="demo"></p>
<script>
Number.prototype.half = function() {
return this.valueOf() / 2;
};
function homzzang() {
var n = 30;
document.getElementById("demo").innerHTML = n.half();
}
</script>
결과보기
결과값: 15