随笔分类 - JavaScript
摘要:XMLHttpRequest (javascript.info) <body> <script> // Create a new XMLHTTPRequest object let xhr = new XMLHttpRequest() xhr.timeout = 5000 // timeout in
阅读全文
摘要:const obj = { name: 'qwer', hobbies: ['op', 'nm'], year: 2022, fn: function () { }, // function ignore reg: new RegExp(), // RegExp {} undefined: unde
阅读全文
摘要:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content
阅读全文
摘要:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content
阅读全文
摘要:let arr = Array.from('vaunt') console.log(arr.slice(1, 3)) let slice = Array.prototype.slice console.log(slice) // [Function: slice] let bounded = sli
阅读全文
摘要:使用Promise封装ajax function ajax (url) { return new Promise((resolve, reject) => { let xhr = new XMLHttpRequest() xhr.onreadystatechange = function () {
阅读全文
摘要:const arr = ['a', 'a', 'a', 'd', 'e', 'f'] for (let i = 0; i < arr.length; ++i) { console.log(`arr.length = ${arr.length}, i = ${i}`) if (arr[i] 'a')
阅读全文
摘要:以下测不出效果, 因为程序逻辑是在function two中执行 <script> function one () { console.info('one') } function two () { setTimeout(() => { console.info('two') }, 1) } fun
阅读全文
摘要:let b = { n1: 11, n2: 22, n3: 44, n4: 55, ns: { n1, n2 } } n1 n2 不是变量, 是b的key let t={22,33} let b = { n1: 11, n2: 22, n3: 44, n4: 55, ns: { this.n1, t
阅读全文
摘要:let i = 0 setTimeout(function (n) { console.log(55, n) }, 1000, setTimeout(function () { console.log(44, i) i++ return i+2 })) 先计算第三参数, 返回值为Timeout对象,
阅读全文
摘要:Date构造函数不使用new时,会忽略参数,返回当前时区的时间对象 new Date()时,创建的是当前时区的时间对象(包含时区) Date.UTC(2020,1,1,1,1,1)可返回一个基于UTC的时间戳,当利用其创建时间对象时,会返回当地时区的时间对象 时间戳是个integer,不可能包含时区
阅读全文
摘要:// var a=222; a=222; function f(){ console.log(a); a=33; } f(); console.log(a) var a=222; // a=222; function f(a){ console.log(a); a=33; } f(); consol
阅读全文
摘要:利用除法Or取模缩小范围 var b=98; switch(parseInt(b/10)){ case 10: console.log('full'); break; case 9: case 8: case 7: case 6: console.log('qualified'); break; d
阅读全文
摘要:// const arr=[1,2,5] // arr.push(9,88) // console.log(arr) // const [x,y,...z]=arr; // console.log(x,z) const b=[11,22,33] // let [x,y,z]=b; // const
阅读全文
摘要:class Serialization { constructor() { console.log('Serialization constructor~~~~~~~'); if (typeof (this.serialize) != 'function') { throw new Referenc
阅读全文
摘要:try { // throw 1; // throw new Number(2) // throw new String('uiop') // throw ('uiop') // throw null; // throw undefined; // throw {}; // throw ()=>1;
阅读全文
摘要:ES6之前,定义一个函数(构造器)对象,使用this定义属性 使用new & 构造器创建一个新对象 function B(x){ console.log('B class') console.log(this); this.x=x; this.show=function(){console.log(
阅读全文
摘要:loop const add=function (x,y){ return x+y; } const sub=function _sub(x,y){ return x-y; } console.log(add(5,7)) console.log(sub(5,8.3)) const sum=funct
阅读全文
摘要:解构 var parts = ['shoulder', 'knees'] var lyrics = ['a', ...parts, 'b', 'c'] // 使用... 解构 console.log(lyrics) function f(x, y, z) { console.log(x + y +
阅读全文
摘要:let b='designate' console.log(b.charAt(2)) console.log(b[2]) console.log(b.toUpperCase()) console.log(b.concat('.com')) console.log(b.slice(3)) consol
阅读全文