current position:Home>Prototype object creation method case JavaScript specific implementation steps

Prototype object creation method case JavaScript specific implementation steps

2022-04-29 10:19:32CSDN Q & A

# My code

<!DOCTYPE html><html>    <head>        <meta charset="utf-8">        <title></title>    </head>    <body>        <p id="111"></p>        <p id="222"></p>        <p id="333"></p>        <script> function Clothes(aaa, bbb) { this.aaa = aaa; this.bbb = bbb; } Clothes.prototype.Clothes_fun = function() { return this.aaa + " yes " + this.bbb }; var clothes1 = new Clothes(" A black dress ", " The clothes Xiao Li wears "); var clothes2 = new Clothes(" Yellow suspender skirt ", " Xiaomei's clothes "); document.getElementById("111").innerHTML = clothes1.Clothes_fun(); document.getElementById("222").innerHTML = clothes2.Clothes_fun(); Clothes.prototype = { Clothes_fun: function() { return this.bbb + " yes " + this.aaa } } var clothes1 = new Clothes(" A black dress ", " The clothes Xiao Li wears "); document.getElementById("333").innerHTML = clothes1.Clothes_fun(); </script>    </body>    <html>

How to add prototype attributes

img




Take the answer :
 Add attribute :Clothes.prototype.type = 'xxxxxx' Add method :Clothes.prototype.Clothes_fun = functio(){  xxxxxx}

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

Random recommended