实践小结 (for in、style.width、overflow、~~)

1、js 数组 for... in.. 中的 key 返回的是 string

for(let key in store.userList){
     if(store.userList[key].loginName==loginName){
         this.slienceList.set(parseInt(key),isvoice);
     }
}

2、style.width接收的需要带px,如果是整数,将无法设置成功。

const resize=()=>{
      camerasRef.current.style.width=`${styles.width}px`;
      camerasRef.current.style.height=`${styles.height}px`;
      camerasRef.current.style.left=`${styles.left}px`;
      camerasRef.current.style.top=`${styles.top}px`;
}

 3、overflow:hidden  内层元素也设置圆角

给父元素中设置overflow:hidden,子元素显示圆角。

 除此之外,overflow还有溢出隐藏、清除浮动、解决外边距塌陷等等作用,参考

 4、值类型和引用类型的区别

function a() {
    var con = {};
    con.name = "ximing";
    con.age = "23";
    console.log("11", JSON.stringify(con));
    b(con);
    console.log("13", JSON.stringify(con));
}

function b(con) {
    con.address = "shanghai";
    console.log("12", JSON.stringify(con));
}
a();
/*
11 {"name":"ximing","age":"23"}
12 {"name":"ximing","age":"23","address":"shanghai"}
13 {"name":"ximing","age":"23","address":"shanghai"}
*/
function c() {
    var age = 36;
    console.log("21", age);
    d(age);
    console.log("23", age);
}

function d(age) {
    age = 50;
    console.log("22", age);
}
c();
/*
21 36
22 50
23 36
*/

 5、~~的作用

let minWidth = ~~(12.56);
console.log(minWidth); //12

~是按位取反运算符 两个就是按位取反后再取反 这里相当于Math.floor() 不过效率高一点

posted @ 2021-06-18 12:06  梁涛999  阅读(61)  评论(0编辑  收藏  举报