大家好!
发送请求时,各位有没有多写好几行程序码的经验呢?
今天就是要简化如此复杂的动作。
我们进入今天的主题吧!
Felix.xhr = function (method, url, callbacks) {
const xhr = new XMLHttpRequest();
Object.keys(callbacks).forEach(function (type) {
xhr.addEventListener(type, callbacks[type].bind(xhr));
});
xhr.open(method, url);
xhr.send();
};
Felix.xhr('GET', 'https://jsonplaceholder.typicode.com/todos/1', {
load: function () {
console.log(this.responseText);
}
});
// Log: { "userId": 1, ..., "completed": false }
差不多也到尾声了,接下来我们要介绍的是函式库的静态方法。
如果对文章有任何疑问,也欢迎在下方提问和建议!
我是 Felix,我们明天再见!
>>: DAY 26:Proxy Pattern,让代理人操作实际的物件
昨天稍微讲解了Dependency Injection,今天要来介绍dagger了。 Dagger ...
前言 非同步程序设计基本上就是没有等待或非阻塞程序的设计模型,在Flutter中,非同步是用Futu...
Start Exam Preparation with Real Huawei H13-611 Du...
属性列举与原型的关系 自订原型 与 原生原型 最大的不同是在可列举(enumerable)的部分 原...
建立 Apps Script 的三种方式 。 今日要点: 》建立 Apps Script 专案 》...