Home > Web Front-end > JS Tutorial > JavaScript Prototype object_javascript skills

JavaScript Prototype object_javascript skills

WBOY
Release: 2016-05-16 18:56:38
Original
1123 people have browsed it

Object-Oriented JavaScript: Using the `Prototype` Property
从JavaScript 1.1开始,它就有了一个内置对象叫Prototype。通过它,可以扩展JavaScript,在对象上编写自定义的属性和方法。举个例子来说。下面自定义了一个叫myTrim的方法,并展示了它的用法。



<script> <BR>String.prototype.myTrim = function(){ <BR>return( this.replace(new RegExp("^([\\s]+)|([\\s]+)$", "gm"), "") ); <BR>} <BR>document.getElementById("textbox").value = " This A Book ".myTrim (); <BR></script>

参考链接:
1. The prototype object of JavaScript
2. Object-Oriented JavaScript: Using the `Prototype` Property
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template