function _f(o) {
console.log("调用call:" + o);
}
class Ajax {
constructor(host) {
this.host = host;
}
get(api) {
console.log(this.host + api);
}
func(o) {
_f.call(this, o);
}
}
//Object.assign 方法向类添加多个方法
Object.assign(Ajax.prototype, {
post(api) {
console.log(this.host + api);
}
});
var ajax = new Ajax("http://microsoft-zh.com.cn");
ajax.get("/api/open/user.get");
ajax.post("/api/open/user.login");
ajax.func("调用");
class utils {
//静态方法
static print(x) {
console.log(x);
}
}
utils.print(1);
/*立即执行*/
//方式一
(function () {
console.log('Welcome to the Internet.');
})();
//方法二
(() => {
console.log('Welcome to the Internet.');
})();
//方法三
let func = new class {
constructor(name) {
this.name = name;
}
getName() {
console.log(this.name);
}
}("名字")
func.getName();
/*类继承*/
class util extends utils {
constructor() {
super();
}
}
util.print(2);
来源:https://www.cnblogs.com/sntetwt/p/11806560.html