摘要: 1.原型链//很少单独使用View Code 1 //定义 SuperClass类,有一个属性property和一个方法getSuperValue 2 function SuperClass() { 3 this.property = true; 4 } 5 SuperClass.prototype.getSuperValue = function() { 6 return this.property; 7 } 8 9 //定义SubClass类,有一个属性subproperty和后来添加的一个方法getSubValue10 function SubClass() {11 ... 阅读全文
posted @ 2012-05-30 16:01 晴天漫步 阅读(253) 评论(0) 推荐(0) 编辑
摘要: 1.创建对象View Code 1 var person = new Object();2 person.name = "RuiLiang";3 person.age = 30;4 person.job = "Teacher";5 person.sayName = function () {6 alert(this.name);7 };8 9 person.sayName();2.工厂模式缺点:不能识别对象View Code 1 function createPerson(name,age,job) { 2 var o = new Object(); 3 阅读全文
posted @ 2012-05-30 15:55 晴天漫步 阅读(235) 评论(0) 推荐(0) 编辑
摘要: 1.URI方法encodeURI()和encodeURIComponent()对URI进行编码encodeURI()不会对本身属于URI的特殊字符进行编码,如冒号,正斜杠,问好,井字等encodeURIComponent()会对任何非标准字符进行编码2.eval() 方法:解释参数中的代码字符串1 var msg = "hello world";2 eval("alert(msg)"); //"hello world"3.Math 对象Math.E 数学中的e的值Math.PI π的值Math.SQRT2 2的平方根Math.abs( 阅读全文
posted @ 2012-05-30 15:39 晴天漫步 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 1.函数内部属性 argumentsarguments用来保存函数的参数,arguments.callee指向拥有arguments对象的函数 1 //阶乘 2 function factorial(num) { 3 if (num <= 1) { 4 return 1; 5 } else { 6 return num*arguments.callee(num-1); //用agreements.callee代替 7 } 8 } 9 10 var trueFactorial = factorial;11 factorial = fu... 阅读全文
posted @ 2012-05-30 15:34 晴天漫步 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 1.创建日期对象1 var now = new Date(); //获得当前系统日期和时间2 var someDate = new Date(Date.parse("May 25,2012"));3 var someDate = new Date("May 25,2012"); //与上相同4 var someDate = new Date(Date.UTC(2010,0)); //GMT时间2010年1月1日凌晨0时5 var someDate = new Date(2010,0); //与上相同6 var so... 阅读全文
posted @ 2012-05-30 15:31 晴天漫步 阅读(179) 评论(0) 推荐(0) 编辑
摘要: 数组的创建第一种:1 var colors = new Array();2 var colors = new Array(20);//创建包含20项的数组3 var colors = new Array("Greg");//创建包含1项,即字符串"Greg"的数组4 var colors = new Array("red","blue","green"); //创建包含3项第二种:1 var colors = ["red","blue","gre 阅读全文
posted @ 2012-05-30 15:27 晴天漫步 阅读(278) 评论(1) 推荐(0) 编辑
摘要: 数字格式化方法toFixed()、toExponential()、toPrecision(),三个方法都四舍五入toFixed() 方法指定小数位个数toExponential() 方法 用科学计数法表示数,参数指定小数位个数toPrecision() 方法自动判断调用toFixed()或toExponential()方法,参数指定所有数的位数1 var num = 99;2 alert(toFixed(2)); //99.003 alert(toExponential(1)); //9.0e+14 alert(toPrecision(1)); ... 阅读全文
posted @ 2012-05-30 09:55 晴天漫步 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 1.字符方法charAt() 、charCodeAt()、fromCharCode()1 var stringValue = "hello world";2 alert(stringValue.charAt(1)); //"e"3 alert(stringValue[1]); //"e"4 alert(stringValue.charCodeAt(1)); //1015 alert(String.fromCharCode(104,101)); //"he"2.返回子字符串方法slice()、substr()、sub 阅读全文
posted @ 2012-05-30 09:50 晴天漫步 阅读(259) 评论(0) 推荐(0) 编辑
摘要: 1.typeof 操作符:用于检测给定变量的数据类型1 var message="some string";2 alert(typeof message); //"string"3 alert(typeof(message)); //"string"4 alert(typeof 100); //"number"typeof操作符可能返回下列字符串:"undefined","boolean","string","number"," 阅读全文
posted @ 2012-05-30 09:44 晴天漫步 阅读(309) 评论(0) 推荐(0) 编辑
摘要: 1.延时脚本运行的方法:方法一:把全部javascript引用放在<body>元素中,页面内容后,如 1 <html> 2 <head> 3 <title>示例1</title> 4 </head> 5 <body> 6 <!--页面内容--> 7 <script type="text/javascript" src="example1.js"></script> 8 <script type="text/javascr 阅读全文
posted @ 2012-05-30 09:30 晴天漫步 阅读(420) 评论(0) 推荐(0) 编辑