日期:2014-05-16 浏览次数:20379 次
Object.extend = function(destination, source) { for (property in source) { destination[property] = source[property]; } return destination; }
<script> function Person(name,age){ //定义一个类,人类 this.name=name; //名字 this.age=age; //年龄 this.sayhello=function(){alert("hello")}; } function Print(){ //显示类的属性 this.funcName="Print"; this.show=function(){ var msg=[]; for(var key in this){ if(typeof(this[key])!="function"){ msg.push([key,":",this[key]].join("")); } } alert(msg.join(" ")); }; } function Student(name,age,grade,school){ //学生类 Person.apply(this,arguments); Print.apply(this,arguments); this.grade=grade; //年级 this.school=school; //学校 } var p1=new Person("jake",10); p1.sayhello(); var s1=new Student("tom",13,6,"清华小学"); s1.show(); s1.sayhello(); alert(s1.funcName); </script>
alert(Math.max(5,8)) //8 alert(Math.max(5,7,9,3,1,6)) //9
var arr=[5,7,9,1] alert(Math.max(arr)) // 这样却是不行的。一定要这样写 function getMax(arr){ var arrLen=arr.length; for(var i=0,ret=arr[0];i<arrLen;i++){ ret=Math.max(ret,arr[i]); } return ret; }
function getMax2(arr){ return Math.max.apply(null,arr); }
var arrLen=arr2.length for(var i=0;i<arrLen;i++){ arr1.push(arr2[i]); }
Array.prototype.push.apply(arr1,arr2)