ITeye博客

JavaScript

共 16 篇文章

js中apply方法的使用

1、对象的继承,一般的做法是复制:Object.extend prototype.js的实现方式是: Object.extend = function(destination, source) { for (property in source) { destination[property] = source[property]; } return destination; } 除此之外,还有种方法,就是:Function.apply(当然使用Function.call也是可以的) apply方法能劫持另外一个对象的方法,继承另外一个对象的属性 Function.apply(obj,arg…

2013-09-25 10:20 · JavaScript

JavaScript 或(||)运算符的妙用

var Book = function(author, title){ this.author = author || 'no author'; this.title = title || 'no title'; }

2013-03-21 15:42 · JavaScript

JavaScript The random() and other Methods of the Math object

The random() Method The Math.random() method returns a random number between the 0 and the 1, not including either 0 or 1. This is a favorite tool of web sites that are trying to display random quotes or random facts upon entry of a web site. You can use Math.random() to select numbers within a cer…

2013-03-18 18:13 · JavaScript

JavaScript Rounding Methods of the Math object

The next group of methods has to do with rounding decimal values into integers. Three methods — Math.ceil(), Math.floor(), and Math.round() — handle rounding in different ways as described here: The Math.ceil() method represents the ceiling function, which always rounds numbers up to the nearest in…

2013-03-18 17:59 · JavaScript

JavaScript The min() and max() Methods of the Math object

2013-03-18 17:51 · JavaScript

JavaScript The min() and max() Methods of the Math object

2013-03-18 17:50 · JavaScript

JavaScript The Number Type

2013-03-18 17:09 · JavaScript

JavaScript Reduction Methods of Array

2013-03-16 08:41 · JavaScript

JavaScript Iterative Methods of Array

2013-03-15 15:12 · JavaScript

JavaScript Location Methods of Array

2013-03-15 15:01 · JavaScript

JavaScript Manipulation Methods of Array

2013-03-15 14:25 · JavaScript

JavaScript Reordering Methods of Array

2013-03-15 13:59 · JavaScript

JavaScript Detecting Arrays

2013-03-15 11:26 · JavaScript

JavaScript中substring和substr区别

1.substring 方法 定义和用法 substring 方法用于提取字符串中介于两个指定下标之间的字符。 语法 stringObject.substring(start,stop) 参数 描述 start 必需。一个非负的整数,规定要提取的子串的第一个字符在 stringObject 中的位置。 stop 可选。一个非负的整数,比要提取的子串的最后一个字符在 stringObject 中的位置多 1。如果省略该参数,那么返回的子串会一直到字符串的结尾。 返回值 一个新的字符串,该字符串值包含 stringObject 的一个子字符串,其内容是从 start 处到 stop-1 处的所有…

2012-12-11 15:03 · JavaScript

JavaScript for...in循环语句

for(变量 in 集合或对象) { 执行语句块 } <script language="javascript"> var as= [1,4,5,6], output=""; for(var x in as){ output += " x= " + as[x]; } alert(output); </script> <script language="javascript"> var as={id:5, name:'test'}; output=""; for(var x in as){ output += x+"="+as[x]; } alert(output); </script>

2012-11-07 14:50 · JavaScript

JavaScript 性能优化之 for 语句

在开发时,很多开发者都会用到for语句与数组做循环来做查询;但手机的性能对循环数据一旦超过5000条数据(例如I9008手机)将会很吃力,所以建议开发者用for语句来做循环查询时,最好用以下的方法来做查询: 把 for(var i = 0, len = array.length; i < len; i++){ if(array[i] == key){ ……… } } 改为: /*JS数组快速模糊查找*/ function JS_cruel_search(array, key){ var re = new RegExp(key); //先把匹配的字符串改过为"┢",然后除了逗号与"┢",所有的…

2012-10-30 17:45 · JavaScript