Detailed explanation of JS rewriting prototype objects
JSPrototype modification and rewriting
There are two ways to modify the js prototype:
1. In the original prototype Add properties and methods to the object: 12
function Person(){ } Person.prototype.name="Mike"; Person.prototype.sayName=function(){ console.log(this.name); } var person= new Person(); person.sayName(); //Mike123456789
2. Override or overwrite the prototype object: 12
function Person(){ } Person.prototype={ "name":"Mike", sayName:function(){ console.log(this.name); } } var person=new Person(); person.sayName(); //Mike1234567891011
Next let’s look at a question: (This question also explains the difference between adding properties and methods directly to the prototype object and overriding or overwriting the prototype object.) 12
function Person(){ } function Animal(){ } var person=new Person(); var animal=new Animal(); Person.prototype={ "name":"Mike", sayName:function(){ console.log(this.name); } } Animal.prototype.name="animal"; Animal.prototype.sayName=function(){ console.log(this.name); } person.sayName(); //error person.sayName is not a function animal.sayName();//animal1234567891011121314151617181920 分析:12 function Person(){ } function Animal(){ } var person=new Person(); var animal=new Animal(); console.log(person. proto ===Person.prototype); //true console.log(animal.proto===Animal.prototype); //true Person.prototype={ "name":"Mike", sayName:function(){ console.log(this.name); } } Animal.prototype.name="animal"; Animal.prototype.sayName=function(){ console.log(this.name); } console.log(person.proto===Person.prototype); //false console.log(animal.proto===Animal.prototype); //true person.sayName(); //error person.sayName is not a function animal.sayName();//animal
Above This is a JS rewriting prototype object that I compiled for you. I hope it will be helpful to you in the future.
Related articles:
Detailed explanation of rewriting and overloading techniques of js methods
Focus on analysis of JavaScript rewriting alert () method skills
Focus on method rewriting in js inheritance
The above is the detailed content of Detailed explanation of JS rewriting prototype objects. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Here's how to convert a MySQL query result array into an object: Create an empty object array. Loop through the resulting array and create a new object for each row. Use a foreach loop to assign the key-value pairs of each row to the corresponding properties of the new object. Adds a new object to the object array. Close the database connection.

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

PHP functions can encapsulate data into a custom structure by returning an object using a return statement followed by an object instance. Syntax: functionget_object():object{}. This allows creating objects with custom properties and methods and processing data in the form of objects.

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service

In PHP, an array is an ordered sequence, and elements are accessed by index; an object is an entity with properties and methods, created through the new keyword. Array access is via index, object access is via properties/methods. Array values are passed and object references are passed.

In C++, there are three points to note when a function returns an object: The life cycle of the object is managed by the caller to prevent memory leaks. Avoid dangling pointers and ensure the object remains valid after the function returns by dynamically allocating memory or returning the object itself. The compiler may optimize copy generation of the returned object to improve performance, but if the object is passed by value semantics, no copy generation is required.

Introducing the new map of Genshin Impact version 4.4. Friends, Genshin Impact 4.4 version also ushered in the Sea Lantern Festival in Liyue. At the same time, a new map area will be launched in version 4.4 called Shen Yu Valley. According to the information provided, Shen Yugu is actually part of Qiaoying Village, but players are more accustomed to calling it Shen Yugu. Now let me introduce the new map to you. Introduction to the new map of Genshin Impact version 4.4. Version 4.4 will open "Chenyu Valley·Shanggu", "Chenyu Valley·Nanling" and "Laixin Mountain" in the north of Liyue. Teleportation anchor points have been opened for travelers in "Chenyu Valley·Shanggu" . ※After completing the prologue of the Demon God Quest·Act 3: The Dragon and the Song of Freedom, the teleportation anchor point will be automatically unlocked. 2. Qiaoyingzhuang When the warm spring breeze once again caressed the mountains and fields of Chenyu, the fragrant

The Request object in PHP is an object used to handle HTTP requests sent by the client to the server. Through the Request object, we can obtain the client's request information, such as request method, request header information, request parameters, etc., so as to process and respond to the request. In PHP, you can use global variables such as $_REQUEST, $_GET, $_POST, etc. to obtain requested information, but these variables are not objects, but arrays. In order to process request information more flexibly and conveniently, you can
