- 浏览: 35886 次
- 性别:
- 来自: 深圳
最新评论
-
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 888实现代码: <iframe id="fra ... -
javascript 复制图片(IE only)
2010-06-23 22:32 1690<img src="http://www. ... -
js中escape,encodeURI,encodeURIComponent三个函数的区别(转)
2010-06-23 16:40 949js对文字进行编码涉及3个函数:escape,enco ... -
html5特征检测
2010-06-22 02:19 1129(Confused? Read Detecting HTML5 ... -
javascript继承,原型,setInterval(前端面试)
2010-06-18 20:09 1452小贤是一条可爱的小狗(Dog),它的叫声很好听(wow),每次 ... -
看看你掌握了js的call和apply没?
2010-06-14 16:07 1111群里出了个题: 下面弹出的结果是什么 ? var a = ... -
修复IE下setTimeout不能传参数的bug
2010-06-11 19:15 2194IE下setTimeout不能参数,如: setTimeout ... -
js获取离生日的天数,和年数
2010-06-10 12:44 1965不计算小时: /* *reg生日 *tod当前日期,从 ... -
parseUrl函数
2010-06-10 10:37 762在外国一博客看到一个很好的 functio ... -
Online and offline events
2010-06-05 13:37 853<!doctype html> <ht ... -
classList属性,class样式列表和操作方法
2010-06-05 10:05 1152firefox3.6新增(目前2010-6-5貌似没有其它浏览 ... -
parseInt
2010-06-01 01:07 852alert(parseInt(0.000001)); ale ... -
chrome arguments bug and firefox regex backdoor
2010-05-29 10:31 865function b(x, y, a) { a = ... -
js之padLeft
2010-04-30 00:11 4420pad1: 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中,你可以使用`Array.prototype.includes()`来检查数组中是否包含某个元素,这类似于PHP的`in_array()`。 总之,`in_array()`是PHP中处理数组查询的强大工具,理解其工作原理和参数设置对于优化代码和...
创建一个JavaScript数组通常使用`new Array()`或直接用方括号`[]`来初始化。例如: ```javascript var array = new Array(); // 或者 var array = []; ``` 然后,你可以使用字符串作为下标来设置或获取数组中的...
此外,示例还展示了如何给JavaScript的基本数据类型(如字符串和数字)添加原型方法,使得可以在任何字符串或数字上调用`in_array`方法。 ```javascript var in_array = function(arr) { var isArr = arr && ...
在JavaScript中,`in_array`函数是一个在PHP中广泛使用的数组操作函数,它用于检查数组中是否存在指定的元素。然而,JavaScript的原生数组对象并没有提供这样的功能。因此,为了实现类似PHP的`in_array`功能,我们...
Javascript 数组 Array 基础介绍 在 JavaScript 中,数组是一种特殊的对象,它们拥有独特的特性。在介绍数组之前,我们需要了解什么是数组。数组是一种类数组的对象,它们拥有对象的特性。当属性名是小而连续的整数...
### JavaScript in 10 Minutes: Key Insights for Intermediate and Advanced Programmers #### Introduction "JavaScript in 10 Minutes" is a concise guide that aims to provide intermediate to advanced ...
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 ...
然而,正如标题和描述中提到的,使用`$.inArray()`时需要注意一些事项,因为JavaScript的弱类型特性可能会导致意外的结果。 `$.inArray(element, array)`方法接收两个参数:`element`是要查找的元素,`array`是待...
避免使用`for in`循环遍历数组,采用经典`for`循环并缓存`length`,明确理解`Array`构造函数的行为,以及正确使用`typeof`和`instanceOf`进行类型检查,这些都是编写高质量JavaScript代码的关键。
在JavaScript中,循环遍历Array和Map是常见的操作,尤其对于数据处理和对象操作至关重要。以下是对各种遍历方法的详细说明: 1. **基本for循环**(eg1、eg5): 基本的for循环是最基础的遍历方式,适用于任何具有...
还可以使用构造函数`new Array()`创建数组,如`var arr = new Array(10);`,这样做会创建一个长度为10的空数组。但在实际编程中,数组字面量用法更直观、简洁。 数组的遍历通常使用for循环或for...in循环。for循环...
JavaScript中的数组Array是编程中非常基础且重要的概念,尤其在JavaScript这种动态类型的脚本语言中,数组具有灵活性和广泛的应用场景。本文主要介绍了Array的基本知识,让我们深入了解一下JavaScript数组的特性。 ...
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 ...
`for(x in newarray)`循环用于遍历数组的所有索引,而`for(i=0; i; i++)`则用于在数组中填充或修改元素。 数组的清空可以通过重新定义数组实现,例如`myarray = new array()`。同时,我们还可以为数组对象自定义...
这一章包含了 JavaScript 的核心对象 Array,Boolean,Date,Function,Math,Number,Object 和 String。这些对象同时在客户端和服务器端的 JavaScript 中使用。 Array 属性 方法 Boolean 属性 方法 Date 属性 方法...
总的来说,虽然JavaScript没有内置的`in_array()`函数,但通过自定义函数或者利用现有的`Array.prototype.includes`和`Array.prototype.indexOf`方法,我们可以轻松地实现相同的功能。同时,扩展基本类型可以提供更...
var a = new Array(1, 2, 3); // 获取数组元素 var firstElement = a[0]; // 遍历数组 for (var i = 0; i ; i++) { console.log(a[i]); } for (var index in a) { console.log(index); // 输出索引 } ``` ####...