• javascript 新知识


     document.compatMode 属性

    BackCompat: Standards-compliant mode is not switched on. (Quirks Mode)  标准模式
    CSS1Compat: Standards-compliant mode is switched on. (Standards Mode) 怪癖模式

    //实现继承
    function
    Super(x, y) { this.x = x; this.y = y; } function Sub(x, y, z) { Super.call(this, x, y); //为子类型的对象实例添加超类型的属性,子类型的对象实例作为超类型的构造函数中的this值 this.z = z; //添加子类型的扩展属性 }

    __proto__指向对象的原型ie所有版本都不支持

    //hasOwnProperty检测某个对象上是否有某个属性,不支持dom对象,不支持检测原型中的属性
    
    // 得到false, 因为不能检测原型链中的属性  
    "hello".hasOwnProperty("split"); 
    
    //String对象的原型上本来就有这个属性,自然返回true  
    String.prototype.hasOwnProperty("split");

    nodeType 比nodeName更好,文本节点#text   document #document  元素节点相当于tagName

    hasChildNodes是否有子节点

    attributes 元素上所有的属性组成的数组

    getAttribute(name)——等于attributes.getNamedItem(name).value
    setAttribute(name, newValue)——等于attribute.getNamedItem(name).value = newValue
    removeAttribute(name)——等于attributes.removeNamedItem(name)

    createComment("注释");//创建注释节点
    
    createDocumentFragment()//创建文档碎片节点
    
    createElement
    
    createTextNode

    以上四种属性浏览器都支持,其他的一些存在兼容性问题,尽量不要用

    清空一个数组的方式,将其leng设置为0

     document.documentMode:ie8+ ie的版本

     ECMAScript认为undefined是从null派生出来的

    //测试 setTimeout 每秒执行的次数 200次/s
    var fireCount = 0;
    
    var start = new Date();
    var timer = setInterval(function(){
        if(new Date() - start >1000)
        {
            console.log(fireCount);
            clearInterval(timer);
            return ;
        }
        fireCount++;
    },0)
    
    //换成while测试会达到400万次/s
    var fireCount = 0;
    var start = new Date();
    while(true){
        if(new Date() - start >1000)
        {
            console.log(fireCount);
            clearInterval(timer);
            break;
        }
        fireCount++;
    }
    
    这个跟函数本身有关,本身就是被设计成慢吞吞的,所以这两个函数计时并不精准
  • 相关阅读:
    JDK1.8源码之HashMap(一)——实现原理、查找及遍历
    JDK1.8源码之ArrayList
    03、Swagger2和Springmvc整合详细记录(爬坑记录)
    02、Java的lambda表达式和JavaScript的箭头函数
    Java-IO流之输入输出流基础示例
    JDBC API 事务的实践
    JDBC API 可滚动可编辑的结果集
    Java虚拟机----垃圾回收与内存分配
    Java数据库连接与查询
    Java虚拟机-对象的创建和访问
  • 原文地址:https://www.cnblogs.com/siqi/p/3239764.html
Copyright © 2020-2023  润新知