尧图建网站 尧图建网站 YAOTU WEB BUILD 免费咨询
ARTICLE DETAIL

资讯详情

深耕网站建设与建站编程的一线实战洞察。

(前端)3.js自定义类样例

(前端)3.js自定义类样例 !DOCTYPE html html head title自定义类型/title /head body h1自定义类型/h1 script //定义一个类 class MyClass { //有参数的构造函数 constructor(a, b) { this._a a; this._b b; } } //类的原型函数定义 MyClass.prototype.GetA function (){ return this._a; } //类的原型函数定义 MyClass.prototype.GetB function() { return this._b; } /script script var myClass1 new MyClass(1, 2); var a1 myClass1.GetA(); var b1 myClass1.GetB(); console.log(a1: a1); console.log(b1: b1); /script /body /html
返回列表