返回博主主页

随笔分类 -  JavaScript

摘要:1代码示例 new Promise(function(resolve, reject) { console.log(1); setTimeout(function() { console.log("First"); resolve(); }, 1000); console.log(2); } ).t 阅读全文
posted @ 2022-01-12 14:50 懒惰的星期六 阅读(54) 评论(0) 推荐(0) 编辑
摘要:1.注意字符串“1”、“0”,数字1、0,空字符串,undefined和null。 var arr = [undefined, null ,1, "1", 0, "0", ""]; arr.forEach((a)=>{ console.log(a,!a,!!a,!!!a); }) 阅读全文
posted @ 2021-11-24 14:39 懒惰的星期六 阅读(67) 评论(0) 推荐(0) 编辑
摘要:背景,需要发起一个网络请求(setTimeout模拟),3秒得到结果。 要求必须在这个网路请求之后才能访问请求到的数据myRes。 要求调用方f4() 和 发起网络请求的f3()都必须用async/await。 假如f4()不用async/await,f3()用。代码执行到promise内部,执行完 阅读全文
posted @ 2021-11-17 16:43 懒惰的星期六 阅读(355) 评论(0) 推荐(0) 编辑
摘要:1. // Example POST method implementation: async function postData(url='15479453.html', data={}) { // Default options are marked with * const response 阅读全文
posted @ 2021-11-11 11:12 懒惰的星期六 阅读(82) 评论(0) 推荐(0) 编辑
摘要:结论先行: yield 句本身没有返回值,或者说总是返回 undefined 。 next 方法可以带一个参数,该参数就会被当作上一个 yield 语句的返回 值。 1. next()不带参数 function* gen(x) { for (var x of [1,2,3,4,5]){ var y 阅读全文
posted @ 2021-10-29 20:51 懒惰的星期六 阅读(138) 评论(0) 推荐(0) 编辑
摘要:1. 生产环境的转换器,建议使用 Thunkify 模块。 // "use strict" function thunkifyy(fn) { return function() { console.log(arguments); //Arguments(2) [8, 9, callee: ƒ, Sy 阅读全文
posted @ 2021-10-29 17:56 懒惰的星期六 阅读(96) 评论(0) 推荐(0) 编辑
摘要:1. JavaScript 语言的 Thunk 函数 JavaScript 语言是传值调用,它的 Thunk 函数含义有所不同。在 JavaScript 语言中,Thunk 函数替换的不是表达式,而是 多参数函数,将其替换成一个只接受回调函数作为参数的单参数函数。 // ES6版本 var Thun 阅读全文
posted @ 2021-10-29 16:39 懒惰的星期六 阅读(125) 评论(0) 推荐(0) 编辑
摘要:1. console.log("ddd") var data = []; for(var i = 0 ; i < 3; i++){ data[i]=function() { console.log(i); } } data[0]();// 3 data[1]();// 3 data[2]();// 阅读全文
posted @ 2021-10-29 11:06 懒惰的星期六 阅读(34) 评论(0) 推荐(0) 编辑
摘要:1. result.value.then function* gen(){ // var url = 'https://api.github.com/users/github'; var url = 'https//:www.baidu.com'; var result = yield fetch( 阅读全文
posted @ 2021-10-28 21:34 懒惰的星期六 阅读(44) 评论(0) 推荐(0) 编辑
摘要:function* gen(x){ try { var y = yield x + 2; } catch (e){ console.log(e); console.log("进入异常catch输出"); } return y; } var g = gen(1); console.log(g.next 阅读全文
posted @ 2021-10-28 19:48 懒惰的星期六 阅读(107) 评论(0) 推荐(0) 编辑
摘要:function dad(){ this.name = "123" this.age = 33 } var dad1 = new dad() var dad2 = new dad() dad.prototype.funcd= ()=>{ console.log("funcdddddd") } //通 阅读全文
posted @ 2021-10-28 16:04 懒惰的星期六 阅读(532) 评论(0) 推荐(0) 编辑
摘要:new 和不 new的区别: 如果 new 了函数内的 this 会指向当前这个 person 并且就算函数内部不 return 也会返回一个对象。 如果不 new 的话函数内的 this 指向的是 window。 function person(firstname,lastname,age,eye 阅读全文
posted @ 2021-10-28 15:38 懒惰的星期六 阅读(607) 评论(0) 推荐(0) 编辑
摘要:构造函数如果采用以下这种方式声明,并不能为Point类生成一个名name为‘y1’的属性property。 Object.assign(Point.prototype, { constructor(x,y){ this.x=x; this.y1=y; }, fun1(){} }); 完整demo如下 阅读全文
posted @ 2021-10-27 14:59 懒惰的星期六 阅读(65) 评论(0) 推荐(0) 编辑
摘要:jQuery 入口函数: (document).ready(function()//);(function(){ // 执行代码 }); JavaScript 入口函数: window.onload = function () { // 执行代码 } jQuery 入口 阅读全文
posted @ 2021-10-24 20:15 懒惰的星期六 阅读(70) 评论(0) 推荐(0) 编辑

Welcome to here

主页
点击右上角即可分享
微信分享提示