In var sample = function() { // constructor code here } sample.prototype.func1 = function() { // func1 code here } sample.prototype.func2 = function() { // func2 code here } /* more sample prototype functions here... */ Then use the following code to instantiate and access the prototype method: var sampleInstance = new sample(); sampleInstance.func1(); sampleInstance.func2(); // call more sample object prototype functions But if we want to rewrite one of the prototype methods without destroying the original var subSample = function() { // constructor code here } // inherit from sample subSample.prototype = new sample(); subSample.prototype.fun1 = function() { // overwrite the sample's func1 } However, if you do not build an inherited class and want to rewrite the prototype method, you can directly use the following code: var sampleInstance = new sample(); sampleInstance.func1 = function() { sample.prototype.fun1.call(this); // call sample's func1 // sampleInstance.func1 code here } We redefined the This is the end of this article about the details of overriding prototype methods in You may also be interested in:
|
<<: XHTML Getting Started Tutorial: Form Tags
>>: Solve the error during connect exception in Docker
First time writing. Allow me to introduce myself....
Preface This article introduces a simple BAT scri...
On mobile devices, flex layout is very useful. It...
Achieve results Implementation Code html <div ...
A system administrator may manage multiple server...
This is a test of the interviewee's basic kno...
Table of contents 1. setTimeout() timer 2. Stop t...
This article shares the specific code of the WeCh...
Table of contents Updatable Views Performance of ...
Preface Seeing the title, everyone should be thin...
Mobile browsers place web pages in a virtual "...
What is high concurrency? The default Linux kerne...
Table of contents 1. Background Architecture Prob...
This article is based on MySQL 8.0 This article i...
The effect is as follows: a page After clicking t...