码迷,mamicode.com
首页 > 编程语言 > 详细

javascript tips and snippets

时间:2015-11-25 23:17:20      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

  • 数字化的Date

 

js中,Date是内置的一种数据类型,虽然直接输出的date格式适合人们阅读,但是对于机器程序来说却有些不方便:

var now=new Date();
console.log(now);//Wed Nov 25 2015 22:02:17 GMT+0800 (中国标准时间)

怎么转换为便于js程序来操作的形式呢?很简单只要在new关键字前面加上一个+即可:

var now=+new Date();
console.log(now);//1448460291345

 javascript Errors:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error

 

try {
  foo.bar();
} catch (e) {
  if (e instanceof EvalError) {
    alert(e.name + ‘: ‘ + e.message);
  } else if (e instanceof RangeError) {
    alert(e.name + ‘: ‘ + e.message);
  } else if (e instanceof InternalError) {
    alert(e.name + ‘: ‘ + e.message);
  }else if (e instanceof ReferenceError) {
    alert(e.name + ‘: ‘ + e.message);
  }else if (e instanceof SyntaxError) {
    alert(e.name + ‘: ‘ + e.message);
  }else if (e instanceof TypeError) {
    alert(e.name + ‘: ‘ + e.message);
  }else if (e instanceof URIError) {
    alert(e.name + ‘: ‘ + e.message);
  }
  // ... etc
}

 

javascript tips and snippets

标签:

原文地址:http://www.cnblogs.com/kidsitcn/p/4996101.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!