前端小知识

    17

一次性函数

function fnc() {
    console.log("x");
    fnc = function() {
        console.log("y");
    }
}
fnc()//x
fnc()//y
fnc()//y

空值过滤

   console.log([undefined, null, "",0,false,NaN,1,2].filter(Boolean))
   //[1,2]

判断数据类型

可判断类型:undefined、null、string、number、boolean、array、object、symbol、date、regexp、function、asyncfunction、arguments、set、map、weakset、weakmap

function DataType(tgt, type) {
    const dataType = Object.prototype.toString.call(tgt).replace(/\[object (\w+)\]/, "$1").toLowerCase();
    return type ? dataType === type : dataType;
}

css单行溢出省略号

overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;

多行溢出省略号

display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;

隐藏元素

//元素不会占用空间,在页面中不显示,子元素也不会显示。
display: none;
//元素隐藏,但元素仍旧存在,占用空间,页面中无法触发该元素的事件。
visibility: hidden;
//元素透明度将为0,但元素仍然存在,绑定的事件仍旧有效仍可触发执行。
opacity: 0;

??默认值

false或0 不执行
false||'a'
0||'a'
false&&'a'
0&&'a'
评论区
共有评论 0
暂无评论