current position:Home>Are there any specific steps to create a prototype, such as JavaScript?

Are there any specific steps to create a prototype, such as JavaScript?

2022-04-29 06:58:58CSDN Q & A

# Prototype object creation method case
javascript
The specific implementation steps are as follows :

a) Create a constructor Clothes().

b) be based on Clothes() newly added 2 Objects clothes1、clothes2.

c) Use prototype Add to constructor type attribute .

d) Use prototype attribute , Give constructors Clothes() add to Clothes_fun Method .

e) Output the results in the page .
yuan Do you have the code ?




Take the answer :

I followed the steps to write down

// a)  Create a constructor Clothes()      function Clothes() {}      // b)  be based on Clothes() newly added 2 Objects clothes1、clothes2      let clothes1 = new Clothes()      let clothes2 = new Clothes()      // c)  Use prototype Add to constructor type attribute       Clothes.prototype.type = 'type'      // d)  Use prototype attribute , Give constructors Clothes() add to Clothes_fun Method       Clothes.prototype.Clothes_fun = function() {        console.log('Clothes_fun')      }      // e)  Output the results in the page       document.write(clothes1 + '<br>')      document.write(JSON.stringify(clothes2))      console.log('clothes1', clothes1)      console.log('clothes2', clothes2)

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/112/202204221325191464.html

Random recommended