zoukankan      html  css  js  c++  java
  • javascript零散要点收集

    1.this永远指向函数对象的所有者

    2.ECMA-262 把对象(object)定义为“属性的无序集合,每个属性存放一个原始值、对象或函数”。严格来说,这意味着对象是无特定顺序的值的数组。

    3.prototype只有函数对象才会有的属性。

    4.对象创建之后为其附加的属性不会被继承。

    5.new 创建对象只能来自于函数对象。

    5.1也可以直接创建对象实例

    6.for in可遍历对象属性

    7.obj.prototype.constructor会输出obj创建时用的函数的文本。

    8.极度延迟

    9.getprototypeof、 instanceof、 typeof

    10.可以复制一个函数对象function fun(){};var prune=fun;

    11.eval就是一个宏。完全可以这么理解

    12.$()[index]可以得到dom对象,内部实现在json对象里有提到。

    13.var isIE = /MSIE/.test(ver); var isFF = /Firefox/.test(ver); //“/MSIE/”得到一个正则表达式对象,然后调用它的test方法

    14.只能在输出流中使用document.write()方法,如果整个文档已经输出完毕,那么这时调用document.write()时会覆盖整个文档

    <html>

    <script>

    document.write("abcd");

    </script>

    <p>aaaa</p>

    <script>

    document.write("<br/>abcd");

    function clickme()

    {

    document.write("assda");

    }

    </script>

    <input type="button" value="adljs" onclick="clickme()"/>

    </html>

    输出结果为

    abcd

    aaaa

    abcd

    点击按钮后变为assda

    15.用name还是id,原先是只能用name来标记一个锚,现在可以用id了,可以把id看成是name的升级版,比如

    <a href="#chapter1">第一章</a>

    <p>asldjfalsdj</p>

    <p>asldjfalsdj</p>

    <p>asldjfalsdj</p>

    <p>asldjfalsdj</p>

    <p>asldjfalsdj</p>

    <p>asldjfalsdj</p>

    <p id="chapter1">asldjfalsdj</p>

     <!--<p name="chapter1">asldjfalsdj</p>等价于上一行-->

    16.<link rel="stylesheet" type="text/css" href="style.css"/>  其中href=hypertext reference rel=relationship

    17.apply 和call的区别和用法 
    两都作用是相同的,只不过语法略有不同,apply的第二个参数是参数数组,call的第一个参数之后是一个参数序列,随便举个例子吧
    经常看到这种用法,如果一个函数接收的参数个数不是固定的,那么可以用apply将一个数组传给这个函数
    我们常见到Func.apply(null,argsArr)实际上可以写成Func(arg1,arg2,...)的形式,但是以数组的方式来调用显然简洁了许多
    arr=[1,3,5,9,2,8,6,0];
    Math.max.apply(null,arr)因为max函数可以接收任意多个参数,并找出其中的最大值,一个个写这些参数显然是不合适的,这时传一个数组进去就解决了
    可以说apply提供了函数传参的第二种选择,那就是让你可以以数组的形式传参。
     
    function callme(name,age)
    {
    this.name=name;
    this.age=age;
    }
    var p={name:"sdsd",age:56};
    callme.apply(p,["sd",23]);//或者callme.call(p,"sd",23)
    alert(p.name);//输出为sd

     18.bind http://msdn.microsoft.com/zh-cn/library/ff841995(v=vs.94).aspx

    语法:function.bind(thisArg[,arg1[,arg2[,argN]]])

    //In the following example, the thisArg object is different from the object that contains the original method.
    //JavaScript
    // Create an object that contains the original function.
    var originalObject = {
        minimum: 50,
        maximum: 100,
        checkNumericRange: function (value) {
            if (typeof value !== 'number')
                return false;
            else
                return value >= this.minimum && value <= this.maximum;
        }
    }
    
    // Check whether 10 is in the numeric range.
    var result = originalObject.checkNumericRange(10);
    document.write(result + " ");
    // Output: false
    
    // The range object supplies the range for the bound function.
    var range = { minimum: 10, maximum: 20 };
    
    // Create a new version of the checkNumericRange function that uses range.
    var boundObjectWithRange = originalObject.checkNumericRange.bind(range);
    
    // Check whether 10 is in the numeric range.
    var result = boundObjectWithRange(10);
    document.write(result);
    // Output: true
    //The following code shows how to use the arg1[,arg2[,argN]]] arguments. The bound function uses the parameters specified in the bind method as the first and second parameters. Any parameters specified when the bound funct//ion is called are used as the third, fourth (and so on) parameters.
    //JavaScript
    // Define the original function with four parameters.
    var displayArgs = function (val1, val2, val3, val4) {
        document.write(val1 + " " + val2 + " " + val3 + " " + val4);
    }
    
    var emptyObject = {};
    
    // Create a new function that uses the 12 and "a" parameters
    // as the first and second parameters.
    var displayArgs2 = displayArgs.bind(emptyObject, 12, "a");
    
    // Call the new function. The "b" and "c" parameters are used
    // as the third and fourth parameters.
    displayArgs2("b", "c");
    // Output: 12

     综上 apply和call是直接调用函数本身,只是函数中this的含义发生了变化,而bind只是将两个对象先行捆绑,调用是发生在这之后。

    相信世界是平的
    谨记四个字“修身养性”
    大江东去浪淘尽英雄,再牛B的人物最后也是一掊土
    向善不是目的,而是抚慰心灵,更多的感受幸福,感谢别人给你行善的机会
    相信老子的话:万物生于有,有生于无,一切的道理都源于一个无法证明的假设
    我是好是坏就自然而然的摆在那里,并不会因为别人的评价而改变什么,我也不需要别人用一张纸来说明我什么,世间最难得的是自由



    支持大额赞助:
  • 相关阅读:
    Hibernate记录(二)
    Hibernate记录(一)
    设计模式:依赖倒转原则(记录一)
    java ssl 使用不同的加密套件,对性能影响很大
    关于在 java 8 下开启 TLS_RSA_WITH_3DES_EDE_CBC_SHA 支持 xp ie8 tls1.0 的正常访问
    JAVA版本8u171与8u172的区别
    java 8: ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
    修改 iis 的端口号: 80 与 443
    HTTPS笔记:使用 SSLEngine 为 aioserver 服务器提供 SSL 访问支持
    总结一下:指针运算
  • 原文地址:https://www.cnblogs.com/sky-view/p/3246585.html
Copyright © 2011-2022 走看看