- 浏览: 34844 次
- 性别:
- 来自: 深圳
最新评论
-
wjjxf:
js 牛人!
修复IE下setTimeout不能传参数的bug -
zhenjia:
标记一下。很多东西可以借鉴 谢谢分享
2008年国外最佳Web设计/开发技巧、脚本及资源总结 -
badboy4471:
标记一下,以后可能用得着呢。草草看了一下。不错。
2008年国外最佳Web设计/开发技巧、脚本及资源总结 -
westlwt:
怀旧一下...
2008年国外最佳Web设计/开发技巧、脚本及资源总结 -
JavaLanguageFun:
很有收藏意义,那天就可能会用到!
2008年国外最佳Web设计/开发技巧、脚本及资源总结
New in JavaScript 1.8.1(Firefox3.5)
Object.getPrototypeOf()
This new method returns the prototype of a specified object.
Using native JSON
Firefox 3.5 has native support for JSON.
New trim methods on the String object
The String object now has trim(), trimLeft(), and trimRight() methods.
New in JavaScript 1.6
Array extras
There are seven new Array methods that can be separated into two categories, item location methods and iterative methods.
The item location methods are:
•indexOf() - returns the index of the given item's first occurrence.
•lastIndexOf() - returns the index of the given item's last occurrence.
The iterative methods are:
•every() - runs a function on items in the array while that function is returning true. It returns true if the function returns true for every item it could visit.
•filter() - runs a function on every item in the array and returns an array of all items for which the function returns true.
•forEach() - runs a function on every item in the array.
•map() - runs a function on every item in the array and returns the results in an array.
•some() - runs a function on items in the array while that function returns false. It returns true if the function returns true for any item it could visit.
For more information see Working with Arrays
New in JavaScript 1.8
JavaScript 1.8 is part of Gecko 1.9 (which is incorporated into Firefox 3).
Array extras
There are two new iterative Array methods included in JavaScript 1.8, specifically:
•reduce() - runs a function on every item in the array and collects the results from previous calls.
•reduceRight() - runs a function on every item in the array and collects the results from previous calls, but in reverse.
Object.getPrototypeOf()
This new method returns the prototype of a specified object.
Using native JSON
Firefox 3.5 has native support for JSON.
New trim methods on the String object
The String object now has trim(), trimLeft(), and trimRight() methods.
//fastest trim http://lifesinger.org/blog/2010/01/fastest-javascript-trim/ if(!String.prototype.trim){ String.prototype.trim=function() { var s=this,whitespace = ' \n\r\t\v\f\u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000', i = 0, j = s.length - 1; while (i < s.length && whitespace.indexOf(s.charAt(i)) != -1) i++; while (j > i && whitespace.indexOf(s.charAt(j)) != -1) j--; return s.substring(i, j + 1); } }
New in JavaScript 1.6
Array extras
There are seven new Array methods that can be separated into two categories, item location methods and iterative methods.
The item location methods are:
•indexOf() - returns the index of the given item's first occurrence.
if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt /*, from*/) { var len = this.length >>> 0; var from = Number(arguments[1]) || 0; from = (from < 0) ? Math.ceil(from) : Math.floor(from); if (from < 0) from += len; for (; from < len; from++) { if (from in this && this[from] === elt) return from; } return -1; }; }
•lastIndexOf() - returns the index of the given item's last occurrence.
if (!Array.prototype.lastIndexOf) { Array.prototype.lastIndexOf = function(elt /*, from*/) { var len = this.length; var from = Number(arguments[1]); if (isNaN(from)) { from = len - 1; } else { from = (from < 0) ? Math.ceil(from) : Math.floor(from); if (from < 0) from += len; else if (from >= len) from = len - 1; } for (; from > -1; from--) { if (from in this && this[from] === elt) return from; } return -1; }; }
The iterative methods are:
•every() - runs a function on items in the array while that function is returning true. It returns true if the function returns true for every item it could visit.
if (!Array.prototype.every) { Array.prototype.every = function(fun /*, thisp*/) { var len = this.length >>> 0; if (typeof fun != "function") throw new TypeError(); var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (i in this && !fun.call(thisp, this[i], i, this)) return false; } return true; }; }
•filter() - runs a function on every item in the array and returns an array of all items for which the function returns true.
if (!Array.prototype.filter) { Array.prototype.filter = function(fun /*, thisp*/) { var len = this.length >>> 0; if (typeof fun != "function") throw new TypeError(); var res = []; var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (i in this) { var val = this[i]; // in case fun mutates this if (fun.call(thisp, val, i, this)) res.push(val); } } return res; }; }
•forEach() - runs a function on every item in the array.
if (!Array.prototype.forEach) { Array.prototype.forEach = function(fun /*, thisp*/) { var len = this.length >>> 0; if (typeof fun != "function") throw new TypeError(); var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (i in this) fun.call(thisp, this[i], i, this); } }; }
•map() - runs a function on every item in the array and returns the results in an array.
if (!Array.prototype.map) { Array.prototype.map = function(fun /*, thisp*/) { var len = this.length >>> 0; if (typeof fun != "function") throw new TypeError(); var res = new Array(len); var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (i in this) res[i] = fun.call(thisp, this[i], i, this); } return res; }; }
•some() - runs a function on items in the array while that function returns false. It returns true if the function returns true for any item it could visit.
if (!Array.prototype.some) { Array.prototype.some = function(fun /*, thisp*/) { var i = 0, len = this.length >>> 0; if (typeof fun != "function") throw new TypeError(); var thisp = arguments[1]; for (; i < len; i++) { if (i in this && fun.call(thisp, this[i], i, this)) return true; } return false; }; }
For more information see Working with Arrays
New in JavaScript 1.8
JavaScript 1.8 is part of Gecko 1.9 (which is incorporated into Firefox 3).
Array extras
There are two new iterative Array methods included in JavaScript 1.8, specifically:
•reduce() - runs a function on every item in the array and collects the results from previous calls.
if (!Array.prototype.reduce) { Array.prototype.reduce = function(fun /*, initial*/) { var len = this.length >>> 0; if (typeof fun != "function") throw new TypeError(); // no value to return if no initial value and an empty array if (len == 0 && arguments.length == 1) throw new TypeError(); var i = 0; if (arguments.length >= 2) { var rv = arguments[1]; } else { do { if (i in this) { var rv = this[i++]; break; } // if array contains no values, no initial value to return if (++i >= len) throw new TypeError(); } while (true); } for (; i < len; i++) { if (i in this) rv = fun.call(null, rv, this[i], i, this); } return rv; }; }
•reduceRight() - runs a function on every item in the array and collects the results from previous calls, but in reverse.
if (!Array.prototype.reduceRight) { Array.prototype.reduceRight = function(fun /*, initial*/) { var len = this.length >>> 0; if (typeof fun != "function") throw new TypeError(); // no value to return if no initial value, empty array if (len == 0 && arguments.length == 1) throw new TypeError(); var i = len - 1; if (arguments.length >= 2) { var rv = arguments[1]; } else { do { if (i in this) { var rv = this[i--]; break; } // if array contains no values, no initial value to return if (--i < 0) throw new TypeError(); } while (true); } for (; i >= 0; i--) { if (i in this) rv = fun.call(null, rv, this[i], i, this); } return rv; }; }
发表评论
-
iframe高度自适应
2010-06-24 16:05 828实现代码: <iframe id="fra ... -
javascript 复制图片(IE only)
2010-06-23 22:32 1642<img src="http://www. ... -
js中escape,encodeURI,encodeURIComponent三个函数的区别(转)
2010-06-23 16:40 926js对文字进行编码涉及3个函数:escape,enco ... -
html5特征检测
2010-06-22 02:19 1087(Confused? Read Detecting HTML5 ... -
javascript继承,原型,setInterval(前端面试)
2010-06-18 20:09 1415小贤是一条可爱的小狗(Dog),它的叫声很好听(wow),每次 ... -
看看你掌握了js的call和apply没?
2010-06-14 16:07 1077群里出了个题: 下面弹出的结果是什么 ? var a = ... -
修复IE下setTimeout不能传参数的bug
2010-06-11 19:15 2131IE下setTimeout不能参数,如: setTimeout ... -
js获取离生日的天数,和年数
2010-06-10 12:44 1909不计算小时: /* *reg生日 *tod当前日期,从 ... -
parseUrl函数
2010-06-10 10:37 725在外国一博客看到一个很好的 functio ... -
Online and offline events
2010-06-05 13:37 816<!doctype html> <ht ... -
classList属性,class样式列表和操作方法
2010-06-05 10:05 1114firefox3.6新增(目前2010-6-5貌似没有其它浏览 ... -
parseInt
2010-06-01 01:07 823alert(parseInt(0.000001)); ale ... -
chrome arguments bug and firefox regex backdoor
2010-05-29 10:31 836function b(x, y, a) { a = ... -
js之padLeft
2010-04-30 00:11 4383pad1: function pad(num, n) { ...
相关推荐
Array.prototype.in_array=function(e){ var r=new RegExp(this.S+e+this.S); return (r.test(this.S+this.join(this.S)+this.S)); }; 用法如下: var arr=new Array(["b",2,"a",4,"test"]); arr.in_array('...
JavaScript use with HTML to create dynamic webpages, language concepts including syntax and flow control statementsvariable handling given their loosely typed naturebuilt-in reference types such as ...
本文实例讲述了Javascript实现Array和String互转换的方法。分享给大家供大家参考,具体如下: Array类可以如下定义: 复制代码 代码如下:var aValues = new Array(); 如果预先知道数组的长度,可以用参数传递长度 ...
built-in reference types such as object and array object-oriented programing powerful aspects of function expressions Browser Object Model allowing interaction with the browser itself detecting the ...
var aValues = new Array(); 如果预先知道数组的长度,可以用参数传递长度 var aValues = new Array(20); ——————如下2种定义方式是一样的——–1——- var aColors = new Array(); aColors[0] = red; ...
Work with JavaScript objects, such as String, Array, Number, and Math Use JavaScript with Scalable Vector Graphics (SVG) and the canvas element Store data in various ways, from the simple to the ...
这一章包含了 JavaScript 的核心对象 Array,Boolean,Date,Function,Math,Number,Object 和 String。这些对象同时在客户端和服务器端的 JavaScript 中使用。 Array 属性 方法 Boolean 属性 方法 Date 属性 方法...
The book includes all the great content included in the JavaScript Bible, 4th Edition, an international bestseller, plus over 400 pages of new material. The Gold Bible features essential new ...
If you’re a programmer new to JavaScript, or even a beginner with little or no programming experience, this latest edition of practical book offers complete, no-nonsense coverage of this essential ...
JavaScript中循环语句不少,for、for in、for of和forEach循环,今天对比Array、Object、Set(ES6)、Map(ES6)四种数据结构循环语句支持的情况及区别。 新建四种数据类型的测试数据 let arr = [1, 2, 3, 4, 5, 6];...
// load an array of three AudioBuffers called 'drums', play them in 8th notes and give them // the sequence drums[0], drums[2], drums[1], drums[2] d = new track() d.sample...
JavaScript 1.6 引入了几个新的Array 方法,具体的介绍见:New in JavaScript 1.6 。这些方法已经被写进了ECMA262 V5。现代浏览器(IE9/Firefox/Safari/Chrome/Opera)都已经支持,但IE6/7/8不支持。jquery的工具...
12) 创建一个数组可用 new Array() 。可以在构造函数参数中指定数组的前n个元素的值。数组的元素可以具有任意类型,甚至是另外一个数组。同一数组中可以存在不同类型的元素。数组的length是可读写的。这也是缩短一个...
Learn to write modern JavaScript not by memorizing a list of new syntax, but with practical examples of how syntax changes can make code more expressive. Starting from variable declarations that ...
这一章包含了 JavaScript 的核心对象 Array,Boolean,Date,Function,Math,Number,Object 和 String。这些对象同时在客户端和服务器端的 JavaScript 中使用。 Array 属性 方法 Boolean 属性 方法 Date ...
Array Literals Section 6.2. Length Section 6.3. Delete Section 6.4. Enumeration Section 6.5. Confusion Section 6.6. Methods Section 6.7. Dimensions Chapter 7. Regular Expressions Section 7.1....
JavaScript数组join()方法加入数组的所有元素为一个字符串。 语法 array.join(separator); 下面是参数的详细信息: separator : 指定字符串分开数组的每个元素。...var arr = new Array("First","Second","Th
var my_array:Array = new Array(); my_array[0] = 1; my_array[1] = 2; my_array[2] = 3; my_array[3] = 4; my_array[4] = 5; trace(my_array.toString()); // Displays 1,2,3,4,5. 此示例输出 1、2、3、4、5 作为 ...
LinqJsSince 2.1.0, I rewrite all to use new features of ES6. The performance be better, memory used less and using deferred execution.对 JavaScript 中原生数组、对象进行扩展, 提供了一些对数据的操作方法...
Traceur 是一个来自 Google 的 Javascript 编译器,通过它可以体验一些很新并且有趣的 Javascript 语言特性,这些多数是还没有被当前浏览器实现的 ECMAScript 标准或草案,比如:数组比较、类、模块、迭代器、方法...