@(JavaScript)[CoffeeScript]
我们常常会使用indexOf()
方法来判断一个值是不是属于一个数组, 但由于IE还没有支持, 我们还是需要做一些兼容性的处理.
var included = (array.indexOf("test") != -1)
# http://zhang.zipeng.info/library/coffeescript/07_the_bad_parts.html | |
# 使用typeof | |
# 这里是jQuery的$.type的实现的例子 | |
type = do -> | |
classToType = {} | |
for name in "Boolean Number String Function Array Date RegExp Undefined Null".split(" ") | |
classToType["[object " + name + "]"] = name.toLowerCase() | |
(obj) -> |
var fs = require('fs'); | |
var iconv = require('iconv-lite'); | |
fs.readFile('./a_uft8.md', function(err, data) { | |
if (err) { | |
console.error(err); | |
} else { | |
var str = iconv.decode(data, 'utf-8'); | |
var str2 = iconv.encode(str, 'gbk') | |
var str3 = iconv.decode(str2, 'gbk') |
<html> | |
<head> | |
<meta name="renderer" content="webkit|ie-comp|ie-stand"> | |
</head> | |
<body> | |
</body> | |
</html> |
[1,2,3,4].filter(function(a){
console.log(this);
console.log('a:'+a);
return a!==this[0];
},[2]);
A Pen by Robert Blecha on CodePen.
// | |
// Regular Expression for URL validation | |
// | |
// Author: Diego Perini | |
// Updated: 2010/12/05 | |
// License: MIT | |
// | |
// Copyright (c) 2010-2013 Diego Perini (http://www.iport.it) | |
// | |
// Permission is hereby granted, free of charge, to any person |
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<style type="text/css"> | |
h2 { margin:0; padding:10px 0; font-size:14px; } | |
.mod-retweet { background:#E4EFF4; border:1px solid #A8D1E0; padding:3px 5px 5px; margin-top:5px; } | |
.mod-retweet .mod-retweet-textarea { background-color: #FFFFFF; border:1px solid #64B2D1; margin-bottom:5px; overflow:hidden; padding:2px; position:relative; zoom:1 } | |
.mod-retweet .mod-retweet-textarea textarea {padding: 0;margin: 0; border:0 none; font-size:12px; height:80px; line-height:1.5em; width:100%; display:block } | |
.mod-retweet .mod-retweet-textarea input { border:0 none; font-size:12px; height:20px; line-height:1.5em; width:100%; } |