`
mengqingyu
  • 浏览: 329161 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

js笔记

阅读更多
//判断是否为数组
var is_array = function(value) {
	return Object.prototype.toString.apply(value) === '[object Array]';
};

//array.push(item...)实现原理
Function.prototype.method = function (name, func) {
	this.prototype[name] = func;
	return this;
}
Array.method('push',function(){
	this.splice.apply(this,[this.length, 0].concat(Array.prototype.slice.apply(arguments)));
	return this.length;
});

//string.replace(searchValue, replaceValue) 美元符号
//$&整个匹配的文本,在匹配的字符串之后插入替换的内容
//$1分组捕获的文本
var oldareacode = /\((\d{3})\)/g;
var p = '(555)666-1212'.replace(oldareacode,'$1-');//p 555-666-1212

//汉字、Unicode转换
var GB2312UnicodeConverter = {
	ToUnicode: function (str) {//汉字转换为Unicode代码
		return escape(str).toLocaleLowerCase().replace(/%u/gi, '\\u');
	}
	, ToGB2312: function (str) {//Unicode代码转换为汉字
		return unescape(str.replace(/\\u/gi, '%u'));
	}
};

//JSLint定义了一组编码约定,这比ECMA定义的语言更为严格。它是一个JavaScript验证工具(非开源),可以扫描JavaScript源代码来查找问题。
Google JSLint 下载地址 http://code.google.com/p/jslint-toolkit/
JSLint http://www.JSLint.com
JavaScript Lint http://www.JavaScriptLint.com/

//标签
JavaScript中,标签标识符与命名变量标识符使用的是不同的命名空间,以避免冲突。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics