前端架构

穿精又带淫゛_ 提交于 2019-12-03 20:17:01

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);

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!