zoukankan      html  css  js  c++  java
  • 什么叫匿名函数

    1,什么叫匿名函数,就是把名字用~!()等特别符号命名,并放在function最前面.执行时不用直接用()不用名称。
    function Test(){}
    ~function(){
    }()


    2,闭包理解
    函数调函数,返加函数
    var test=function(){return function(){}}  

    3,arguments用法.函数调用时,发果找不到对应传参。直接到到无参。arguments可以取到所有传进参数。
    function test(){
    alert(arguments[0])
    }
    test("0001","0002")
    4,声明函数与函数表达式。声明函数有优先,表达式则一定在执行之前。
    alert(test());OK
    function(test()){alert("OK")};
    alert(test2()); 出错
    var test2=function(){alert("OK")};
    5,Object对像带属性:Prototype,constructor,hasOwnProperty(property)
    Person.prototype.printName=function(){
    }
    对所有对像生效。
    person.share=0;自己属性优先于prototype是共享.
    6, prototype instanceof Array
    typeof(obj)

    =============================
    jquery
    $.fn.xx === Person.prototype.xx
    jQuery.extend({
    min: function(a, b) { return a < b ? a : b; },
    max: function(a, b) { return a > b ? a : b; }
    });
    jQuery.min(2,3); // 2
    jQuery.max(4,5); // 5
    var result=$.extend({},{name:"Tom",age:21},{name:"Jerry",sex:"Boy"}) 合并去除重复。
    result={name:"Jerry",age:21,sex:"Boy"}
    合并深度.true深度合并。
    var result=$.extend( true, {},
    { name: "John", location: {city: "Boston",county:"USA"} },
    { last: "Resig", location: {state: "MA",county:"China"} } );
    $.fn.extend(tooltip) = $.prototype.extend(tooltip) = $.fn.tooltip

    7,对像是引用关系。一个变个个变.
    var a = {name: 'nswbmw 1'};
    var b = a;
    a.name="test2"
    console.log(a.name);
    console.log(b.name);

    exports 是指向的 module.exports 的引用{}
    exports.sayName = function() {
    console.log(name);
    }
    module.exports = function(r) {
    return r * r * Math.PI;
    }
    exports=function(r){} 出错,因为
    require() 返回的是 module.exports 而不是 exports


    var circle=require('./circle.js');返回对像module.exports

    circle.js:
    exports.area = function (r) {
    return PI * r * r;
    };

    exports.circumference = function (r) {
    return 2 * PI * r;
    };

    module.exports = function(r) {
    return r * r * Math.PI;
    }
    console.log(circle.area(4));
    console.log(area(4));

  • 相关阅读:
    【BZOJ 4151 The Cave】
    【POJ 3080 Blue Jeans】
    【ZBH选讲·树变环】
    【ZBH选讲·拍照】
    【ZBH选讲·模数和】
    【CF Edu 28 C. Four Segments】
    【CF Edu 28 A. Curriculum Vitae】
    【CF Edu 28 B. Math Show】
    【CF Round 439 E. The Untended Antiquity】
    【CF Round 439 C. The Intriguing Obsession】
  • 原文地址:https://www.cnblogs.com/jayruan/p/5167900.html
Copyright © 2011-2022 走看看