zoukankan      html  css  js  c++  java
  • 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++;
    }
    
    这个跟函数本身有关,本身就是被设计成慢吞吞的,所以这两个函数计时并不精准
  • 相关阅读:
    mysql修改数据库的存储引擎(InnoDB)
    如何查看进程/服务是否启动
    Spark Streaming 入门
    Graphlab create的基本使用
    构建房屋预测回归模型
    构建应用深层特征的图像检索系统
    构建商品评价的分类器
    Elastic Static初识(01)
    《Linux就该这么学》笔记(二)
    《Linux就该这么学》笔记(一)
  • 原文地址:https://www.cnblogs.com/siqi/p/3239764.html
Copyright © 2011-2022 走看看