zoukankan      html  css  js  c++  java
  • [label][JavaScript]七个JavaScript技巧

    重点:http://www.javascriptkit.com/

    create an object:

    var car = new Object();

    car.colour = 'red';

    car.wheels = 4;

    car.hubcaps = 'spinning';

    car.age = 4;

    The same can be acchieved with:

    var car = {

      colour : 'red',

      wheels: 4,

      hubcaps:'spinning' ,

      age: 4

    }

    注意:But what happens when you use invalidUserInSession? The main gotcha in this notation is IE. Never ever leave a trailing comma before the closing curly brace or you’ll be in trouble.

    var moviesThatNeedBetterWriters = new Array(

      'Transformers', 'Transformers2' , 'Avatar' , 'Indiana Jones 4'

    );

    var moviesThatNeedBetterWriters = [

      'Transformers', 'Transformers2' , 'Avatar' , 'Indiana Jones 4'

    ];

    对数组中的数据进行排序,可以直接使用sort(),参考文章:http://www.javascriptkit.com/javatutors/arraysort.shtml

    Notice that you can not use sort() on a number array because it sorts lexically(词汇方面).

    var numbers = [23 , 342 , 87 , 145];

    numbers.sort(function(a , b){ return a - b;}); //ascending,升序

    numbers.sort(function(a , b){return b - a;});//descending,降序

    Math.max(12 , 123 , 3 , 2 , 433 , 4);//Math.max() return the largest number form a list of parameters

    Because this tests for numbers and returns the largest one , you can use it to test for browser support of cetain properties.

    var scrollTop = Math.max(

      doc.documentElment.scrollTop,

      doc.body.scrollTop

    );

  • 相关阅读:
    机械迷城MAC下载及攻略
    今晚是个难眠之夜
    div高度自适应
    代码高亮
    windows live writer
    Java连接redis的使用示例
    luogu4360 锯木厂选址 (斜率优化dp)
    poj1651 Multiplication Puzzle (区间dp)
    hdu3506 Monkey Party (区间dp+四边形不等式优化)
    poj1236/luogu2746 Network of Schools (tarjan)
  • 原文地址:https://www.cnblogs.com/shuman/p/3954303.html
Copyright © 2011-2022 走看看