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

    );

  • 相关阅读:
    爬取校园新闻首页的新闻的详情,使用正则表达式,函数抽离
    网络爬虫基础练习
    Hadoop综合大作业
    hive基本操作与应用
    用mapreduce 处理气象数据集
    熟悉常用的HBase操作
    爬虫大作业
    熟悉常用的HDFS操作
    数据结构化与保存
    获取全部校园新闻
  • 原文地址:https://www.cnblogs.com/shuman/p/3954303.html
Copyright © 2011-2022 走看看