day10

01.js

const callback = function() {
    console.log('hello, timeout!')
}

let a = setTimeout(callback, 3000);
console.log(a);
clearTimeout(a)

1.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=1200, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const callback = function() {
            console.log('hello, timeout');
        }

        let a = setTimeout(callback, 0);
        console.log('同步执行!');
        console.log(a);
        clearTimeout(a);
        
        let b = setInterval(callback, 3000);
    </script>
</body>
</html>

json.js

const oStudent = {
    "student Name": "Tianguiping",
    age: 20,
    org: ["lovo", "smart"],
    len: null,
    len1: undefined,
    course: { name: "java", day: 1 },
    learn: function () {
      console.log("hello, student");
    },
    learn2() {
      console.log("hello2");
    },
  };

 let a =  JSON.stringify(oStudent,null,2);
 console.log(a);


 const b = `{"student Name":"Tainguiping","age":20,"org":["lovo","smart"],"len":null,"course":{"name":"java","day":1}}`;
 const oStudent1 = JSON.parse(b);
 //console.log(oStudent1);

 for (let p in oStudent1) {
     console.log(p);
 }

math.js

// Math对象
let x = 1, y = 2, z = 3;
console.log(`最大值为:${Math.max(x,y,z)}`);

const scores = [1,2,2,32,12,3,333];
console.log(`最大值为:${Math.max(...scores)}`);

let a = Math.random() * 6;  // 0 - 1.0之间的小数
console.log(a);
console.log(Math.floor(a) + 1);   //1 - 6

// Math.floor(Math.random()*6) +1   --- 生成1-6之间的一个随机数

object.js

const oStudent = {
  "student Name": "Tianguiping",
  age: 20,
  org: ["lovo", "smart"],
  len: null,
  len1: undefined,
  course: { name: "java", day: 1 },
  learn: function () {
    console.log("hello, student");
  },
  learn2() {
    console.log("hello2");
  },
};

delete oStudent.len;
console.log(oStudent.len); // undefined
oStudent.learn();
oStudent.learn2();
oStudent["learn"]();
console.log(oStudent["age"]);
console.log(oStudent["student Name"]);

const oStudent1 = new Object();
oStudent1.studentName = "Tainguiping";
oStudent1.age = 20;

// 计算属性
let a = "student",
  b = "Name";
const oStudent1 = {
  [a + b]: "Tianguiping",
  age: 20,
};

console.log(oStudent1);

// 简写
let studentName = "Tianguiping",
  age = 20;
const oStudent2 = {
  studentName: studentName,
  age: age,
};

const oStudent3 = { studentName, age }; // ES6
console.log(oStudent3.studentName);

const name = Symbol("name");
const superGirl = { [name]: "Supergirl" };
console.log(superGirl[name]); // -> "Supergirl"
console.log(superGirl.name); // undefined;

const realName = Symbol("real name");
superGirl[realName] = "kara Danvers"; // 添加新属性
console.log(superGirl[realName]); // -> 'kara Danvers'
console.log(superGirl); // -> { [Symbol(name)]: 'Supergirl', [Symbol(real name)]: 'kara Danvers' }
const daredevil = {
  [name]: "Daredevil",
  [realName]: "Matt Murdoch",
};
console.log(daredevil); // -> { [Symbol(name)]: 'Daredevil', [Symbol(real name)]: 'Matt Murdoch' }

// 判断属性或者方法是否存在
const teacher = {
  name: "xiao",
  age: 49,
};

// 1. 通过 in 运算符判断
console.log("name" in teacher); // true
console.log("sName" in teacher); // false

// 2. 逻辑表达式
if (teacher.name !== undefined) {
  console.log("teacher.name 存在!");
}

// 3.用hasOwnProperty()
if (teacher.hasOwnProperty("name")) {
  console.log("我有这个属性啦!");
}

// 对象属性遍历
const oStudent4 = {
  "student Name": "xiaojichao",
  age: 49,
  org: ["lovo", "smart"],
  len: null,
  len1: undefined,
  course: { name: "java", day: 1 },
  learn: function () {
    console.log("hello, student");
  },
  learn2() {
    console.log("hello2");
  },
};

console.log(oStudent4.course.name);

// for (let p in oStudent4) {
//     console.log(p);
// }

// console.log(Object.keys(oStudent4));

// for (let p of Object.keys(oStudent4)) {
//     console.log(p);
// }

// const values1 = Object.values(oStudent4);
// console.log(values1);

// for (let value of values1) {
//     console.log(value);
// }

const [a, b] = Object.entries(oStudent4);
console.log([a, b]);

for (let [a, b] of Object.entries(oStudent4)) {
  console.log(`key:${a}, value:${b}`);
}

// 按引用赋值
const aa = { name: "xiao" };
const bb = aa;
bb.name = "xiao1";
console.log(aa.name);

function greet(greeting, name, age) {

}

function greet({ greeting, name, age }) {
  return `${greeting}! 我是${name},今年${age}岁。`;
}
let a = greet({ greeting: "师傅,你好", age: 10, name: "Bart" });
console.log(a); // -> 师傅,你好!我是Bart,今年10岁。
function greet({ greeting = "Hello", name, age = 18 }) {
  return `${greeting}!我是${name},今年${age}岁。`;
}
let b = greet({});
console.log(b); //-> Hello!我是undefined,今年18岁。
let c = greet({ name: "Lisa", age: 8 });
console.log(c); // -> Hello!我是Lisa,今年8岁。

// this

const dice = {
    side: 6,
    roll() {
        return Math.floor(Math.random()* this.side) + 1;
    }
}

console.log(dice.roll());

let x = 1, y = 2, z = 3;
console.log(Math.max(x,y,z));

const myMath1 = {
    max: function(...num) {
        return num;
    }
};

myMath1.max();

pattern.js

const pattern = /javascript/;
console.log(pattern.test('javascript'));

// RegExp

const pattern1 = new RegExp('javascript');
let a = pattern1.test('javascript');
console.log(a);

/dog/.test('hot dog'); //true
/d.g/.test('dag'); //true
/d.g/.test('ddddddddg')  //true
/d.g/.test('doooog'); //false
/dog/.test('ddddoggg'); //true


wrapper.js

// 包装器对象

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

// 0, undefined, null, '', NaN
const oStudent = {};

if (oStudent.name) {
    console.log('hello');
}


// Number
let num = new Number(123);
console.log(num.length);

let b = Number.parseInt(112121.001);
console.log(b);

let c = Number.parseFloat("123.00");
console.log(c);
console.log(Number.isInteger(c));

let d = Number.isInteger(123.8);
console.log(d);

// String 对象

let e = String.fromCharCode(97);
e = String.fromCodePoint('0x10');
console.log(e);
let d = 'Tianguiping';
console.log(d.slice(1,3));
console.log(d);

d.concat('xiao');
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值