您当前的位置: 首页 > 

暂无认证

  • 3浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

JS中ES6类和对象

发布时间:2020-09-11 12:02:14 ,浏览量:3


<!DOCTYPE html> <html> <head> <title></title> <style type="text/css"> </style> </head> <body> <script type="text/javascript"> /*function Person(myName, myAge)
	{
		this.name=myName;
		this.age=myAge;
		this.hi=function()
		{
			console.log("h1");
		}
	}
	/*Person.prototype.type="cyg";
	Person.prototype.say=function()
	{
		 console.log(this.name, this.age);
	};
	*/ //也可以这样写. /*Person.prototype={
		constructor:Person,
		type:"cyg",
		say:function()
		{
			console.log(this.name, this.age);
		}
	};*/ class Person { constructor(myName, myAge) { this.name = myName; this.age = myAge; this.hi = function () { console.log("hi"); } } run() { console.log("run"); } } // Person.prototype.type = "人"; // Person.prototype.say = function () { //     console.log(this.name, this.age); // }; let obj={constructor:Person,type:"cyg",say:function() { console.log(this.name, this.age); }}; Person.prototype=obj; let p = new Person("lnj", 34); console.log(p); </script> </body> </html> 
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.0745s