2020-11-30

1.html

<script>//定时器函数
    const callback=function(){
        console.log('hello world')
    }
    let a=setTimeout(callback,3000);
    console.log('同步执行!');//同步执行在异步执行之前
    console.log(a);
    clearTimeout(a);//回调函数则不能执行了
    let b=setTimeout(callback,3000);
        </script>

2.内置对象

// 包装器对象
// 一、Boolean 对象
// 1.当做构造函数来用
let bool = new Boolean(true);
console.log(typeof bool); //object
console.log(bool === true); // false
console.log(bool.valueOf()); // true
console.log(bool.toString()); // true
// 2.当做函数来用
let a = Boolean(‘true’);
console.log(a); // true
// 0,undefined,’’,NaN 转换时会变成 false
let b = Boolean(0);
console.log(b); // false
let b = Boolean([]);
console.log(b); // true
// 二、Number 对象
let num = new Number(123);
console.log(num.length);
// 1.静态方法
// 转换成整型
let c = Number.parseInt(111232.9009)
console.log©
let d = Number.parseFloat(11123)
console.log(d)
// 判断是否是整数
let e = Number.isInteger(111.8)
console.log(e)
// 2.实例方法
let f = (345).toLocaleString(“zh-hans-CN-u-nu-hanidec”);
console.log(f);
// 三、String 对象
// 1.静态方法
let h = String.fromCharCode(97); // 转 ASCLL 码
h = String.fromCodePoint(‘0x99’);
console.log(h);
// 2.实例方法
let j = ‘yangqian’;
console.log(j.slice(1,3)); // an —— 左开右闭
console.log(j);
let j1 = ‘yangqian’;
console.log(j1.concat(‘xyz’));
// 四、JSON 对象
// 五、Math 对象
// 六、RegExp 对象

json

const oStudent4 = {
“student Name” : ‘yangqian’,
sge : 22,
org : [‘love’,‘smart’],
course : {‘name’:‘java’,‘day’:1},
len : null,
len1 : undefined,
learn :function() {
console.log(‘hello,student4!’);
},
learn1() {
console.log(‘learn1’)
}
};
let a = JSON.stringify(oStudent4,null,2);
console.log(a);
const b = {
“student Name”: “yangqian”,
“sge”: 22,
“org”: [
“love”,
“smart”
],
“course”: {
“name”: “java”,
“day”: 1
},
“len”: null
}
const oStudent1 = JSON.parse(b);
for (let p in oStudent1){
console.log§;
}

Math对象

// Math 对象
let x = 1, y = 2, z = 3;
console.log(最大值为:${Math.max(x,y,z)});
const scores = [1,2,2,32,12,2,333];
console.log(最大值为:${Math.max(...scores)});
let a = Math.random() * 6; // 0-1.0 之间的小数(这里×6时指0-5之间)
console.log(a);
// 向下取整数
console.log(Math.floor(a) + 1); // 1-6之间
Math.floor(Math.random(a *6)) + 1 // 生成 1-6 之间的

Object

const oStudent={
studentName:‘zhenghairong’,
age:21,
org:[‘lovo’,‘smart’],
len:null,
lenl:undefined,
course:{name:‘java’,day:1},
learn:function(){
console.log(‘hello student’)
},
learn1(){
console.log(‘hello1 world’)
}
};
for(let p in oStudent4){
console.log§;
}
console.log(Object.keys(oStudent));
for (let p of Object.keys(oStudent1)){
console.log§;
}
console.log(Object.vaules(oStudent4));
delete oStudent.len;
console.log(oStudent.len);//得到undefind结果
oStudent.learn();
oStudent.learn1();
oStudent’learn’;
console.log(oStudent[‘age’]);
console.log(oStudent[‘student Name’]);
//构造函数
const oStudent1=new Object();
oStudent1.studentName=‘zhenghairong’;
oStudent1.age=21;
//计算属性
let a=‘student’,b=‘Name’;
const oStudent1={
[a+b]:‘zhenghairong’,
age:21
};
console.log(oStudent1)
//简写
let studentName=‘zhenghairong’,age=21;
const oStudent2={
studentName:studentName,
age:age
};
const oStudent3={studentName,age}; //ES6
console.log(oStudent3.studentName);
//判断属性或者方法是否存在
//1.通过in运算符来判断
const teacher={
name:‘zhenghairong’,
age:21
};
console.log('name’in teacher);
console.log('sname’in teacher);
//2.逻辑表达式
if(teacher.naem !==undefined){
console.log(‘teacher.name 存在’)
}
//3.直接用对象的一个hasOwnProperty()
if(teacher.hasOwnProperty){
console.log(‘我有这个属性’)
}
const vaules1=Object.vaules(oStudent4);
console.log([a,b]);
for(let [a,b] of Object.defineProperties(oStudent4)){
console.log(key:${a},value:${b});
}
//按引用赋值
const aa={name:‘zhenghairong’};
const bb=aa;
bb.name=‘zhengdada’;
console.log(aa.name);
let x=1,y=2,z=3;
console.log(Math.max(x,y,z));
const myMath1={
max:function(…num){
return num;
}
}

正则表达式

// 创建正则表达式
// 方式一
const pattern = /javaScript/;
pattern.test(‘javaScript’);
// 方式二
// RegExp
const pattern1 = new RegExp(‘javaScript’);
let a = pattern1.test(‘javaScript’);
console.log(a);
let a = /dog/.test(‘hot dog’);
console.log(a); // true
let a = /d.g/.test(‘hot dog’);
console.log(a); // true
let a = /11|22/.test(‘2232432’);
console.log(a); // true
let b = (new RegExp(‘1\+1’).test(‘1+1’));
console.log(b);
// 匹配原则
// abcd任意一个出现就可以
let c = /[abcd]/.test(‘php’);
console.log©;
// a-d里面某一个在就可
let c1 = /[a-d]/.test(‘pbp’);
console.log(c1);
let d = /[\d]/.test(1233);
console.log(d);
let f = /l{0}k/.test(‘loooook’);
console.log(f);

String对象

let e=String.fromCharCode(97);
e=String.fromCharCode(‘97’)
console.log(e);
let d=‘zhenghairong’;
console.log(d.slice(1,3));
console.log(d);
d.concat(‘zhenghairong’)
const b={"student Name":"zhenghairong","age":21,"org":["lovo","smart"]}
const oStudent=JSON.parse(b);
for(let p in oStudent){
console.log§;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值