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

JavaScript Prototype object_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:56:381137browse

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