首页 > 其他分享 >Visual Studio Code= 笔记

Visual Studio Code= 笔记

时间:2022-10-03 18:11:07浏览次数:49  
标签:Code console log return Visual let var Studio true

第一次ES6

// let school = 'magedu'
// console.log(school.charAt(2))// g
// console.log(school[2])// g
// console.log(school.toUpperCase())// MAGEDU
// console.log(school.concat('.com'))//连接
// console.log(school.slice(3))//切片,支持负索引
// console.log(school.slice(3, 5))
// console.log(school.slice(-2, -1))
// console.log(school.slice(-2))

// let url = "www.magedu.com"
// console.log(url.split('.'))
// console.log(url.substr(7, 2))//返回子串从何处开始,取多长
// console.log(url.substring(7, 10))//返回子串,从何处开始,到什么为止

// let s = 'magedu.edu'
// console.log(s.indexOf('ed'))// 3

// console.log(s.indexOf('ed', 4))// 7
// console.log(s.replace('.edu', '.com'))
// s = ' \tmag edu \r\n'
// console.log(s.trim())//去除两端的空白字符。trimLeft、trimRight是非标函数,不要用



// let a='tom'
// // var b=" hello \" "
// var b=18
// // console.log(b)
// c=`my name is ${a} my age is ${b}`
// console.log(c)



// str="hello world12!!";
// console.log(str)

// console.log(a)
// var a
// console.log(a)
/*
a=200;
var b=300;let c=123;
console.log(a)
console.log(b)
console.log(c)
const d=12;
// d=223;
console.log(d)
*/
/*
var a=112;
function hello(){
    // var a=12
    a=12
    console.log(a)
}
console.log(a)
// console.log(hello(a))
hello()
*/
// 类型转换
//弱类型
// console.log('=====string=====')
// console.log(a = 3 + 'magedu', typeof (a))
// console.log(a = null + 'magedu', typeof (a))
// console.log(a = undefined + 'magedu', typeof (a))
// console.log(a = true + 'magedu', typeof (a))
//数字
// console.log('=====number=====')
// console.log(a = null + 8, typeof (a))
// console.log(a = undefined + 8, typeof (a))//undefined没法转换成一个对应的数字
// console.log(a = true + 8, typeof (a))//1
// console.log(a = false + 8, typeof (a))
//boolean
console.log('=====bool=====')
// console.log(a = null + true, typeof (a))
// console.log(a = null + false, typeof (a))
// console.log(a = undefined + true, typeof (a))//unde
// console.log(a = undefined + true, typeof (a))//undefined没法转换成一个对应的数字
// console.log(a = undefined + false, typeof (a))//1
// console.log(a = null & true, typeof (a))
// console.log(a = undefined & true, typeof (a))
// //短路
// console.log(a = null && true, typeof (a))//逻辑运算符,null直接就是false短路
// console.log(a = false && null, typeof (a))//逻辑运算符,false短路返回false
// console.log(a = false && 'magedu', typeof (a))//boolean
// console.log(a = true && 'magedu', typeof (a))//字符串
// console.log(a = true && '', typeof (a))//字符串

// // null
// console.log('=====null=====')
// console.log(a = null + undefined, typeof (a))


let trees = new Array("redwood", "bay", "cedar", "oak", "maple");
console.log(0 in trees);// returns true,0在数组对象的index中
console.log(3 in trees);// returns true,3在数组对象的index中
console.log(6 in trees);// returns false,6不在数组对象的index中
console.log("bay" in trees);// return false,bay不是属性,它是值
console.log("length" in trees);// returns true,length是对象的属性
console.log('~~~~~~~~~~~~~~~~~~~~')


delete trees[3];
console.log(3 in trees);// return false
for (var i = 0; i < trees.length; i++)
    console.log(trees[i]);
console.log('~~~~~~~~~~~~~~~~~~~~')

// Custom objects
let mycar = {
    color: "red",
    model:'Accord',
    year: 1998
};
console.log("color" in mycar);// returns true
console.log("model" in mycar);// returns false
console.log('year' in mycar)// true



// x = 42;
// var y = 43;
// let z = 60;
// myobj = new Number();
// myobj.h = 4;// create property h
// console.log(delete x);// returns true (can delete if declared implicitly)
// console.log(delete y);// returns false (cannot delete if declared with var)
// console.log(delete z);// returns false
// console.log(delete Math.PI);// returns false (cannot delete predefined properties)
// console.log(delete myobj.h);// returns true (can delete user-defined properties)
// console.log(delete myobj);// returns true (can delete if declared implicitly)
// console.log('~~~~~~~~~~~~~~~~~~~~')

// var trees = new Array("redwood", "bay", "cedar", "oak", "maple");
// for (var i = 0; i < trees.length; i++)
//     console.log(trees[i])
// console.log('==================')
// delete trees[3];//数组中元素被删除,但空着的位置是undefined
// for (var i = 0; i < trees.length; i++)
//     console.log(trees[i])



// b=new String('abc')
// console.log(b instanceof String);
// a=new Number(1)
// console.log(a instanceof Number);
// console.log(typeof(a))
// console.log(typeof(100))
// console.log(typeof(typeof(100)))

// if(typeof('abc')=="string"){
//     console.log(true)
// }



// console.log(Number.parseInt('1100'));
// let i = 0
// let a = i++
// console.log(a, i)//打印什么0 1
// console.log(a, i++)//打印什么0 1
// a = ++i
// console.log(a, i)//打印什么3 3

// i = 0;
// let a = ++i + i++ + i++ + i;
// console.log(a);//答

//++i + i++ + i++ + i
//1   + 1  + 2   + 3
//      2    3

//2*3 + 3/4 + 4*5


// console.log(1,100 > '200')// false
// console.log(2,300 > '200')// true
// console.log(3,300 > '2000')// false
// console.log(4,3000 > '2a')// false
// console.log(41,3000>NaN) //false
// console.log(5,'3000' > '2000')// true
// //宽松比较
// console.log(6,300 == '300')// true
// console.log(7,'200' == '200')// true
// //严格比较 ===
// console.log(8,300 === '300')// false
// console.log(9,'200' === '200')// true


// console.log(('3' > 30) ? '真' : '假')

// let a=4,b=5,c=1>2?'true':'false'
// console.log(a,b,c)


function hello() {
    let a = 1;
    var b = 2;
    c = 3
}

//let d = 100
if (1) {
    let d = 4;
    var e = 5;
    f = 6
    if (true) {
        console.log(d)
        console.log(e)
        console.log(f)
        console.log('-------------')
        g = 10
        var h = 11
    }
}
//console.log(a) // 不可见
// console.log(b) //不可见
// console.log(c) //不可见?

//console.log(d) //块作用域使用let,不可见;但是块外的d可见
// console.log(e)//块作用域使用var,可见
// console.log(f)//块作用域隐式声明,可见
// console.log(g)//可见
// console.log(h)//可见



// function * inc(){
//     let i=0;
//     while (1){
//         yield (++i);
//     }
// }
// g=inc();
// console.log(g.next().value)
// console.log(g.next())
// console.log(g.next())
// console.log(g.next())


let x = 5
switch (x) {
    case 0:
    console.log('zero')
    break;
    case 1:
        console.log('one');
    case 2:
        console.log('two');
    case 3:
        console.log('three');
        break;
    case 5:
    case 4:
        console.log('four');
    default:
        console.log('other')
    break;
}




// a=10
// switch(a){
//     case 1:
//     case 3:
//     case 5:
//         console.log('奇数');
//         break;
//     case 2:
//         // console.log('2')
//     case 4:
//     case 6:
//         console.log('偶数');
//         break;
//     default:
//         console.log('null')
// }

arr=[10,20,30,40]

function add(x,y){
    return x+y;
}
var obj={
    p1:1,
    p2:'abc',
    p3:[1,2,3],
    p4:add
}


for(x=0;x<arr.length;x++){
    console.log(x,arr[x]);
}
console.log('------------')
for(x in arr){//index
    console.log(x,arr[x])
}
console.log('------------')
for (x in obj){
    console.log(x,obj[x])
}
console.log(obj['p4'](3,5))
console.log('------------')
for(x of arr){
    console.log(x)
}
for(x of obj){//x 是value
    console.log(x)
}






// for (let i = 0; i < 10; i++) {
//     console.log(i)
// }
// console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')

// for (var x = 0, y = 9; x < 10; x++, y--) {
//     console.log(x * y)
// }
// console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
// for (let i = 0; i < 10; i += 3) {
//     console.log(i)
// }



// arr=[10,20,30,40]

// for (let x=0;x<arr.length;x++){
//     console.log(x,arr[x])
// }


for(let i=1;i<10;i++){
    line='';
    for(let j=1;j<=i;j++){
        line+=`${j}*${i}=${i*j}`;
        console.log(line,'|')
    }
}



function sum(arr){
    for(let x in arr){
        console.log(x,typeof(x),arr[x])
    }
    for(let x of arr){
        console.log(x,typeof(x));
    }
    for(let x=0;x<arr.length;x++){
        console.log(x,typeof(x),arr[x])
    }
}
sum([3,6,9])


// var add=function _add(a,b){
//     console.log(_add)
//     console.log(add)
//     return a+b
// };
// var add = function (a, b) {
//    console.log(add)
//     return a + b
// };


// console.log(_add(3,5))
// console.log(add(3, 5))

// x=10
// var sum=function(x){
//     result=0
//     while(x){
//         console.log(x);
//         result+=x
//         x--;
//         return result
//     }
// };
// console.log(sum(10));





// var map = (fn,arr)=>{
//     let newarr=[];
//     for(i in arr){
//         newarr[i]= fn(arr[i]);
//     }
//     return newarr
// }
// let newarr=map((x)=>{return ++x;},[1,2,3,4])
// console.log(newarr)
// let newarr=map((x)=>++x,[1,2,3,4])
// console.log(newarr)
// let newarr=map(x=>++x,[1,2,3,4])




// let counter=function(){
//     let i=0;
//    return function inc(){
//         return ++i;
//     }
    // return c
    
///}
// d=counter()
// console.log(d())
// console.log(d())
// console.log(d())
// console.log(d())



// for(x=1;x<10;x++){
//     line='';
//     for(y=1;y<=x;y++){
//         //res=x*y
//         //line+=`${y}*${x}=${res}`;
//         line +=`${y}*${x}=${x*y} `  ;
//         if(x==y){
//             console.log(line,'|');
//         }
//     }
// }

/*
function b(){
    console.log('b func')
};

function a(fn){
    console.log('a func');
    return fn;
}

func=a(b);
func();
*/
/*
let counter=function ()
{
    let i=0;
    return ()=>++i;
    // return function inc(){
    //     return ++i;
    // }
    //return inc;
}
c=counter()
console.log(c());
console.log(c());
console.log(c());
console.log(c());
*/
/*
var map=function _map(fn,arr){
    let newarr=[]
    for(x in arr){
        newarr[i]=fn(arr[i]);
    }
    return newarr;
}
newarr=map(function (x){return ++x},[1,2,3,4])

*/
var map = (fn, arr)=> {
    let newarr = []
    for (i in arr) {
        newarr[i] = fn(arr[i]);
    }
    return newarr;
}
//newarr = map( (x)=> { return ++x }, [1, 2, 3, 4]);
//newarr=map((x)=> ++x,[1,2,3,4]);
newarr=map(x=>++x,[1,2,3,4]);

console.log(newarr)






/*
//匿名函数
const add=function(x,y){
    return x+y;
};
console.log(add(4,6));

//有名字的函数表达式
const sub=function fn(x,y){
    return x-y 
};
console.log(sub(5,3))
//console.log(fn(3,2)) //fn只能用在函数内部

//有名字的函数表达式
const sum=function _sum(n){
    let result=0;
    if (n==1) return 1;
    return result+=n+_sum(--n) //_sum只能内部使用   
};
console.log(sum(4))
*/

// const add=(x,...args)=>{
//     console.log(args);
//     console.log(x)
//     console.log(arguments)

// }
// arr=[1,2,3,4]
// add(...arr)

// var obj={
//     a:'abc'
// }
// console.log(obj.a)


// function A(x){
//     console.log('A class')
//     this.x=x;
// }
// console.log(typeof(A))

// a=new A(100);
// console.log(a);

//定义类
// function Point(x,y){
//     this.x=x;
//     this.y=y;
//     this.show=()=>console.log(this,this.x,this.y);
//     console.log('Point~~~~~~');
// }
class Point{
    constructor(x,y){
        this.x=x;
        this.y=y;
        //this.show=function(){ console.log(this.x, this.y) };
        //this.show=()=>{console.log(this,this.x,this.y)};
    }
    show(){
        console.log(this,this.x,this.y)
    }
}

// console.log(Point)
// p1=new Point(4,5);
// console.log(p1);
// console.log('---------')

class Point3D extends Point{
    constructor(x,y,z){
        super(x, y);
        this.z = z;
        //this.show =function(){console.log('show 3D',this.x,this.y,this.z); }
       // this.show=()=>{console.log('show 3D',this,this.x,this.y,this.z)}
    
    }
    show(){
        super.show();
        console.log('-----',this.z);
    }  
    static print(){
        // console.log('3D Point')
        return "3D Point"
    }
}



//继承
// function Point3D(x,y,z){
//     Point.call(this,x,y);
//     this.z=z ;
//     console.log('Point3D~~~~~~~~');
// }

console.log(Point3D.print())

// console.log(Point3D)
p2=new Point3D(14,15,16);
// console.log(p2);
// p2.show();
console.log(p2.constructor.print());


// var school={
//     name:'magedu',
//     getNameFunc:function(){
//         console.log('b',this.name);
//         console.log('a',this);
//         return ()=>{
//             console.log(this==global);
//             return this.name;
//         }
//     }
// }

// console.log(school.getNameFunc()(school))

// func=school.getNameFunc() //return new func 

// console.log(func())

// console.log(func.apply(school,[1,2,3]))


// console.log('c',school.getNameFunc()());

class School{
    constructor(){
        this.name='magedu';
        this.getNameFunc=()=>{
            console.log('b', this.name);
            console.log('a', this);
            return () => {
                console.log(this == global);
                return this.name;
            }
        }
    }
}
school=new School();
func=school.getNameFunc()//return new function 
console.log(func());


// try{
//     throw new Number(1);
// }catch (error){
//     console.log(error);
//     console.log(typeof(error));
//     console.log(error.constructor.name);
// }
// 创建一个类
// class Person {
//     // 构造器方法
//     constructor(name, age) {
//         // 构造器中的this是谁?类的实例对象
//         this.name = name
//         this.age = age
//     }
//     // 类中的一般方法
//     speak() {
//         console.log(`我叫${this.name}`)
//         // 一般方法speak方法放在了哪里?
//         // 答:类的原型对象上,供实例使用
//         // 通过Person实例调用speak时,speak中的this就是Person实例
//     }
// }
// // 创建一个Person的实例对象
// const p1 = new Person('张三', 18)
// p1.speak()
// // 创建一个Student类,继承了Person类
// class Student extends Person {

//     constructor(name, age, grade) {
//         // 调研父类的构造器,注意:必须在最开始
//         super(name, age)
//         this.grade = grade
//     }

// }
// // 创建一个Student类的实例对象
// const s1 = new Student('小张', 18, 3)
// s1.speak()


// function breakfast(dessert,drink,...foods){
//     console.log(dessert,drink,...foods)
// }

// breakfast('cake','coffee','apple','orange')


// let fruits=['apple','banana']
//     foods=['cake',...fruits]

// console.log(fruits)
// console.log(...fruits)
// console.log(foods)





// undifined
// var a; //如果声明了某个变量,但是未对他赋值,则该变量是Undifined类型
// console.log(a)

//null 站一个对象位置
// var obj=new Animal()
// var obj=null 
// console.log(2 == true) //false

// console.log(1 + 'hello')//1hello
// console.log('hello' + true)//hellotrue

// console.log(parseInt(3.14));
// console.log(parseInt('3.14a'));
// console.log(parseInt("a3.14")); //NaN,当字符串转换成数字失败时就是NaN,属于Number

// console.log(NaN == 0);//false
// console.log(NaN > 0);//false
// console.log(NaN < 0);//false
// console.log(NaN == NaN);//false  //NaN数据在表达式中一定结果为false,除了!=
// console.log(NaN!=0) //true

// var i=10;
// var s='hello';
// var b=false;
// var u=undefined;
// var n=null;
// var obj=new Object();
// console.log(typeof (i))//number
// console.log(typeof (s))//string
// console.log(typeof (b))//boolean
// console.log(typeof (u))//undefined
// console.log(typeof (n))//object
// console.log(typeof (obj))//object












/**
 var beyond={
    formedIn:'1983',
    foundedIn:'香港',
    artist:['黄家驹','黄家强','黄贯中','叶士龙']
}
// beyond.formedIn='1983';
// beyond['foundIn']='香港'
// console.log(beyond)
beyond.showArtist=function (){
    for(var i=0;i<this.artist.length;i++){
        console.log(this.artist[i])
    }
}
beyond.showArtist();
var property;
for (property in beyond){
    console.log(beyond[property]);
}
 */





/**
 showMessage=function (e){
    alert(e)
}
showMessage('Hello!!')
 
 */


/**
 
var i=0
while(i<10){
    i++;
    if(i%2===0){
        continue;
    }
    console.log(i);
}

 */


// 28.在文档中创建并插入新的节点.mp4
//29.insertBefore - 在指定的位置插入节点.mp4
// 33.addEventListener - 为对象绑定事件.mp4

/*
var trackCD1=[]
typeof(trackCD1)
trackCD1=['长城','农民','不可一世']
// console.log(trackCD1)//[ '长城', '农民', '不可一世' ]
// console.log(trackCD1.length)//3
// console.log(trackCD1[0])//长城
// console.log(trackCD1[1])//农民
trackCD1[3]='Bye-Bye'
// console.log(trackCD1)//[ '长城', '农民', '不可一世', 'Bye-Bye' ]
trackCD1.push('遥望','温暖的家乡')
//console.log(trackCD1)//[ '长城', '农民', '不可一世', 'Bye-Bye', '遥望', '温暖的家乡' ]
console.log(trackCD1.pop())//温暖的家乡
//console.log(trackCD1)//[ '长城', '农民', '不可一世', 'Bye-Bye', '遥望' ]
console.log(trackCD1.shift())//长城
delete trackCD1[3]
//console.log(trackCD1)//[ '农民', '不可一世', 'Bye-Bye', <1 empty item> ]
console.log(trackCD1.splice(3)) //[ <1 empty item> ]
console.log(trackCD1)//[ '农民', '不可一世', 'Bye-Bye' ]
var trackCD2=['可否冲破','快乐王国']
var tracks=trackCD1.concat(trackCD2)
console.log(tracks)//[ '农民', '不可一世', 'Bye-Bye', '可否冲破', '快乐王国' ]
*/






/*
var weight=160;
var weightIncrease="2.5斤"
a=weight+weightIncrease
console.log(a)
console.log(parseFloat(weightIncrease))
console.log(parseInt(weightIncrease))
b=weight+parseFloat(weightIncrease)
console.log(b)
*/



/**
 var beyond={
    formedIn:'1983',
    foundedIn:'香港',
    artist:['黄家驹','黄家强','黄贯中','叶世荣']
}
beyond.showArtist=function(){
    for(var i=0;i<this.artist.length;i++){
        console.log(this.artist[i])
        document.writeln(this.artist[i])
        
    }
}

beyond.showArtist()
console.log(beyond)
 
 */





/**
 var arr=[
    {name:'小丽',age:18},
    {name:'小米',age:20}
];
for (var item of arr){
    console.log(item.name,item.age)
}
var obj={
    0:'小美',
    1:'小丽'
}
for(let key in obj){
    console.log(key,obj[key])
}
var arr=['美美','丽丽']
for(let key in arr){
    console.log(key,arr[key])
}
for(let val of arr){
    console.log(val)
}
 */


// for(let item in obj.items()){
//     console.log(item)
// }




/**
 var week=['星期天','星期一','星期二','星期三','星期四','星期五','星期六']
// for(var i=0;i<week.length;i++){
//     console.log(week[i])
// }
for(let val of week){
    console.log(val)
}
// 区别主要是for of可以拿到键值,而for in可以拿到键名
ar={a:1,b:2,c:3}
for(let val in ar){
    console.log(val)
    console.log(ar[val])
}
arr=['a','b','c','d']
for(let val of arr ){
    console.log(val)
}

 */

/*  weather="下雨"
switch(weather){
    case '下雨':
        alert('忧郁');
        break;
    case '晴天':
        alert ('心情不错');
        break ;
    default:
        alert('心情糟糕');
        break; 
}
  
 * /








/**
 
 var weather='下雨' ,temprature=26
if ((weather==='晴天')&&(temprature<=26)){
    alert('心情不错')
}else if('下雨'){
    alert('忧郁')
}else{
    alert('心情糟糕')
}
 */


// var words = '宁浩网是个网站'
// console.log(words.length) //7
// console.log(words.charAt(0)) //宁
// console.log(words.charAt(words.length - 1)) //站
// console.log(words.indexOf('网'))//2
// console.log(words.lastIndexOf('网'))//5
// console.log(words.substring(0, 3))//宁浩网
// console.log(words.replace('宁浩网','Hulu'))

// var words = '宁浩网,是个网站'
// console.log(words) //宁浩网,是个网站
// console.log(words.split(','))//[ '宁浩网', '是个网站' ]
// var newWords=words.split(',')
// console.log(newWords)
// console.log(newWords[0])
// console.log(newWords[1])



// m=new Map()
// m.set(1,'a');
// m.set(2,'b');
// m.set(3,'c');
// console.log(m);

//forEach方法只能遍历,没有返回值
// let t=m.forEach((value,key)=>[key,value])
// console.log(t)

//利用数组的map最终返回新的集合的特性
// t=[...m.values()].map(item=>item+100);
// console.log(t);



// function sum(a,b,c){
//     return a+b+c
// }
// console.log(sum(1,6,8))

// function sum(a){
//     return(b)=>{
//         return(c)=>{
//             console.log('c')
//             return a+b+c
//         }
//     }
// }
// console.log(sum(2))

// class Serialization{
//     constructor(){
//         console.log('Serialization constructor~~~');
//         if (typeof (this.stringify) !== 'function') {
//             throw new ReferenceError('should define stringify.');
//         }
//     }
// }

// class Point extends Serialization {
//     constructor(x, y){
//         console.log('Point Constructor~~~~');
//         super();//调用父构造器
//         this.x = x;
//         this.y = y;
//     }

//     stringify(){
//         return `<Point ${this.x}-${this.y}`
//     }
// }

// //s = new Serialization(); // 构造Serialization失败
// p = new Point(4,5); //构造子类对象时,调用父类构造器执行也会失败

// class A extends Object{};
// console.log('b',A)

// const A1=class{
//     constructor(x){
//         this.x=x;
//     }
// }
// console.log(A1)
// console.log(new A1(100).x)

// const B=class extends Object{
//     constructor(){
//         super();
//         console.log('B constructor');
//     }
// }
// console.log(B)
// b=new B()
// console.log(b)

// const x=(Sup)=>{
//     return class extends Sup{
//         constructor(){
//             super();
//             console.log('d','C constructor');
//         }
//     };
// }
// const C=Sup=>class extends Sup{
//     constructor(){
//         super();
//         console.log('e','C constructor');
//     }
// };

// cls=C(A)
// console.log('a',cls)
// c=new cls();
// console.log('3',c);
// c1=new (C(Object))()

// function sum(...numbers){
//     return numbers.reduce((preValue,currentValue)=>{
//         return preValue+currentValue
//     })
// }

// console.log(sum(1,2,3,4))

// class Person extends Object{
//     constructor(name,age,props){
//         super(props)
//         this.name=name
//         this.age=age
//         console.log('constructor',this.props)
//     }
// }
// person=new Person('tom','16')
// console.log(person)



/*

class Serialization{
    constructor(){
        console.log('Serialization constructor~~~');
        if (typeof (this.stringify) !== 'function') {
            throw new ReferenceError('should define stringify.');
        }
    }
}
// const Serialization=Sup=>class extends Sup{
//     constructor(){
//         console.log('Serialization constructor~~~')
//         super(...args)
//         if (typeof (this.stringify) !== 'function') {
//             throw new ReferenceError('should define stringify.');
//         }
//     }
// }

class Point  {
    constructor(x, y){
        console.log('Point Constructor~~~~');
        super();//调用父构造器
        this.x = x;
        this.y = y;
    }
}

class Point3D extends Serialization(Point){
    constructor(x,y,z){
        super(x,y);
        this.z=z;
    }
    stringify(){
        return `<Point3D ${this.x},${this.y},${this.z}>`
    }
}
let p3d=new Point3D(70,80,90);
console.log(p3d.stringify());
*/

/*let food=new Map()
let fruit={}, cook=function (){},dessert='Egg';
food.set(fruit,'Cake');
food.set(cook,'刀叉');
food.set(dessert,'Tea');

console.log(food)
console.log(food.size);
console.log(food.get(fruit));
console.log(food.get(cook));
food.delete(dessert);
console.log(food.has(dessert));
console.log(food.forEach((value, key) => {
    console.log(`${key}--${value}`)
}))
*/

/*
class Person{
    constructor(name,birthday){
        this.name=name,
        this.birthday=birthday 
    }
    intro(){
        return `${this.name},${this.birthday}`
    }
}
class Chef extends Person{
    constructor(name,birthday){
        super(name,birthday)
    }
    intro(){
        console.log(this.name,this.birthday)
    }
}
let wanghao=new Chef('wanghao','1980-03-20');
wanghao.intro()
*/

/**
 class Chef {
    constructor(food) {
        this.food = food,
            this.dash = []
    }
    get menu() {
        return this.dash
    }
    set menu(dish) {
        return this.dash.push(dish)
    }

   static cook(food) {
        console.log(food)
    }
}
Chef.cook('Tomato') 
 */




/**
 class Chef {
    constructor(food){
        this.food=food
    }

/**
 let desserts=new Set(['Pisa', 'Cake' ,'蛋挞'])
desserts.add('笑脸');
desserts.add('笑脸')

console.log(desserts)
console.log(desserts.size)
console.log(desserts.has('Cake'))
desserts.delete('Cake')
console.log(desserts)
desserts.forEach(dessert=>{
    console.log(dessert)
})
desserts.clear()
console.log(desserts)


 */

/*
class Chef {
    constructor(food) {
        this.food = food,
        this.dash=[]
    }
    get menu(){
        return this.dash 
    }
    set menu(dish){
        return this.dash.push(dish)
    }

    cook() {
        console.log(this.food)
    }
}
let wanghao = new Chef('Tomato')
console.log(wanghao.menu='佳佳求');
console.log(wanghao.menu='pisa');
console.log(wanghao.menu)
*/



/**
 class Chef {
    constructor(food){
        this.food=food
    }
    cook(){
        console.log(this.food)
    }
}
let wanghao=new Chef('Tomato')
wanghao.cook()
 */


/**
 let chef=function* (foods) {
    for (var i=0;i<foods.length;i++){
        yield foods[i]
    }
}
let wanghao = chef(['Tomato',"Egg"])
console.log(wanghao.next())
console.log(wanghao.next())
console.log(wanghao.next())
 * 
 */


/**
 function * chef(){
    yield 'Tomato',
    yield "Egg"
}
let wanghao=chef()
console.log(wanghao.next())
console.log(wanghao.next())
console.log(wanghao.next())
 */




/**
 *function chef(foods){
    let i=0;
    return{
        next(){
            let done=(i>=foods.length);
            let value=!done?foods[i++]:undefined;
            return {
                value: value,
                done: done
            }
        }
       
    }   
}
let wanghao=chef(['Tomato','Egg']);
console.log(wanghao.next());
console.log(wanghao.next());
console.log(wanghao.next());

 * @param {*} foods 
 * @returns 
 */


/**
 let breakfast={
    getDrink(){
        return "Tea"
    }
}
let dinner={
    getDrink(){
        return "Coffee"
    }
}
let Sunday={
    __proto__:breakfast,
    getDrink(){
        return super.getDrink() + 'Milk'
    }

}
console.log(Sunday.getDrink())
 
 */


/**
 let breakfast = {
    getDrink() {
        return 'Tea';
    }
};
let dinner = {
    getDrink() {
        return 'Beer'
    }
};
let sunday={
    __proto__:breakfast
}
console.log(sunday.getDrink())
console.log(Object.getPrototypeOf(sunday)===breakfast)
sunday.__proto__=dinner 
console.log(Object.getPrototypeOf(sunday)===dinner)


 */

/**
 let breakfast={
    getDrink(){
        return 'Tea';
    }
};
let dinner={
    getDrink(){
        return 'Beer'
    }
};
let sunday=Object.create(breakfast);
console.log(sunday.getDrink())
console.log(Object.getPrototypeOf(sunday)===breakfast)

Object.setPrototypeOf(sunday,dinner)
console.log(sunday.getDrink())
 */


/**
 let breakfast={}
Object.assign(breakfast,{drink:'Beer'})
console.log(breakfast)
 */



/*
console.log(+0 == -0)//true
console.log(+0 === -0)//true
console.log(NaN == NaN)//false
console.log(Object.is(NaN, NaN))//true
console.log(Object.is(-0, +0))//false
*/

/**
 let food={}
let drink='hot drink'
food.dessert='Cake'
food[drink]='Tea'

console.log(food)



let breakfast=function superBreakfast(){

}
console.log(breakfast.name)

 * 
 */



/**
 * 
 简单来说就是它们两者都可以用于遍历,不过for in遍历的是数组的索引(index),
 而for of遍历的是数组元素值(value)
 var obj={a:1,b:2,c:3}
for (let key in obj){
    console.log(key,obj[key])
}
//a 1 b 2 c 3

const array1=['a','b','c']
for (const val of array1){
    console.log(val)
}
//a b c 
 
 */
/*

for in更适合遍历对象,当然也可以遍历数组,但是会存在一些问题,

比如:

index索引为字符串型数字,不能直接进行几何运算

var arr=[1,2,3]
for (let index in arr){
    let res=index+1
    console.log(res)
}


*/

/***
 * 
 for of遍历的是数组元素值,而且for of遍历的只是数组内的元素,不包括原型属性和索引

 var arr=[1,2,3]
arr.a=123 
Array.prototype.a=123 
for (let value of arr){
    console.log(value)
}
//1 2 3

for of适用遍历数/数组对象/字符串/map/set等拥有迭代器对象(iterator)的集合,
但是不能遍历对象,因为没有迭代器对象,但如果想遍历对象的属性,
你可以用for in循环(这也是它的本职工作)或用内建的Object.keys()方法

var myObject={
    a:1,
    b:2,
    c:3
}
for(var key of Object.keys(myObject)){
    console.log(key+':'+myObject[key])
}
//a:1 b:2 c:3

 */
// console.log(false&&0)

// console.log(true && 0)
// console.log(0 && true)
// console.log(0 && false)
// console.log(01 && 02)

// console.log(null && true)
// console.log(NaN && true)
// console.log(NaN && null)
// console.log(null && NaN)

// console.log(undefined && true)
// console.log(false && undefined)

// console.log(3<<2)

// console.log(null == undefined) //true
// console.log("NaN" == NaN)//false
// console.log(5 == NaN)//false
// console.log(NaN == NaN)//false
// console.log(NaN != NaN)//true
// console.log(false == 0)//true
// console.log(true == 1)//true
// console.log(true == 2)//false
// console.log(undefined == 0)//false
// console.log(null == 0)//false
// console.log("5" == 5)//true





class List extends React.Component {
constructor (props) {
super (props);
this.state = {
1ist: [1, 2, 3],
activeIndex: -1
};
activate(index) {
this.setState({ activeIndex: index });
render () {
const { list, activeIndex } = this.state;
const lis = list.map(
(item, index) => {
const cls = index === activeIndex ? 'active': ';
return (
<1i
key={index}
className={cls}
onClick=>{() => this.activate(index)}>
</1i>
);
return (
<ul>{lis}</ul>
);
3
ト

render() {
        return (
            <div>
                <input type="text" ref={input => this.todoInput=input}/>
                <button onClick={this.add}>Submit #{this.props.count + 1}</button>
            </div>
        )
    }
}

 

标签:Code,console,log,return,Visual,let,var,Studio,true
From: https://www.cnblogs.com/mengdie1978/p/16750925.html

相关文章

  • Latex编码错误:inputenc Error: Unicode char ́ (U+0301)
    遇到这个报错信息,大概率是因为你的bib文件或者tex正文里出现了这个长得像e的字符:é解决办法很简单,你只需要在tex最前面(就是\usepackage那一坨地方)加上这么一行声明就好了......
  • 【合集】AtCoder 比赛题解
    PartAABCABC266(A-Ex)ABC267(A-G)ABC268(A-D)ABC269(A-F)ABC270(D-E)ABC271(C-F)PartBARCARC148(C)......
  • LeetCode 1367. Linked List in Binary Tree
    原题链接在这里:https://leetcode.com/problems/linked-list-in-binary-tree/题目:Givenabinarytree root anda linkedlistwith head asthefirstnode. Ret......
  • LeetCode 75 突破:环形链表 II
    LeetCode75学习计划适用于想为技术面试做准备但不确定应该聚焦于哪些题目的用户。学习计划中的题目都是经过精心挑选的,Level1和Level2学习计划是为初级用户和中级用户......
  • codeforces/AtCoder补题整理
    目录cf1738CEvenNumberAddicts(博弈/记忆化搜索)题意题解cf1739EResetKEdges(树,二分+贪心)题意题解cf1730DPrefixesandSuffixes(字符串,思维)题意题解cf1734DS......
  • LeetCode 363. Max Sum of Rectangle No Larger Than K
    原题链接在这里:https://leetcode.com/problems/max-sum-of-rectangle-no-larger-than-k/题目:Givenan mxn matrix matrix andaninteger k,return themaxsum......
  • Visual Studio批量删除所有注释
    ——上方工具栏—搜索—在文件中替换(或者Command+Shift+H)——勾选上​​正则表达式​​搜索,查找//.*\n,替换为空即可......
  • LeetCode 2365. Task Scheduler II
    原题链接在这里:https://leetcode.com/problems/task-scheduler-ii/题目:Youaregivena 0-indexed arrayofpositiveintegers tasks,representingtasksthatneed......
  • vscode中快速声明数据类型
    如何快速声明数据类型上面这张图letobj1=reactive({listArr:[],backArr:[{name:'张三',age:10,info:'本科'}],age:100,name:'',flag:......
  • Codeforces Global Round 22 C. Even Number Addicts(博弈论)
    https://codeforces.com/contest/1738/problem/C题目大意:给定n个数字,Alice先手,Bob后手;拿完之后,Alice数字总和为奇数时Alice获胜,否则Bob获胜。问我们给定n个数字,双方......