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

    );

  • 相关阅读:
    ZOJ 3609 Modular Inverse (水题)
    ZOJ 3607 Lazier Salesgirl (贪心)
    POJ 1730 Perfect Pth Powers (枚举||分解质因子)
    POJ 2262 Goldbach's Conjecture (素数判断)
    LA 3135 Argus (优先队列)
    uva 11991 (map vector 嵌套)
    hdu 1022 Train Problem I(stack)
    poj 1837 blance (01背包)
    hdu 1242 rescue (优先队列 bfs)
    hdu 3033 I love sneakers!(分组背包)
  • 原文地址:https://www.cnblogs.com/shuman/p/3954303.html
Copyright © 2011-2022 走看看