<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>原型+构造函数创建工厂</title> </head> <body> <script> function CreateStuent(name,score,grade) { this.name=name; this.score=score; this.grade=grade; CreateStuent.prototype.showname=function () { alert("我叫:"+this.name) } } var s1=new CreateStuent("小明",90,"五年级") var s2=new CreateStuent("小红",80,"四年级") s1.showname() s2.showname() </script> </body> </html>
js构造函数及原型对象
最新推荐文章于 2022-11-15 23:00:51 发布