07 2012 档案
js 继承
摘要:一、用function实现:function Person(name) { this.name = name;}Person.prototype.getName = function() { return this.name;}function Author(name, books) { this.inherit=person; this.inherit(name); this.books = books; }var au=new Author("dororo","Learn much");au.name或者同等效力的:function Person(n 阅读全文
posted @ 2012-07-31 16:00 rorodo 阅读(1749) 评论(0) 推荐(0)
js权威指南9-1例子:实例属性、实例方法、类属性、类方法
摘要:// We begin with the constructorfunction Circle(radius) { // r is an instance property, defined and initialized in the constructor. this.r = radius;}// Circle.PI is a class property--it is a property of the constructor function.Circle.PI = 3.14159;// Here is an instance method that computes a ... 阅读全文
posted @ 2012-07-27 15:11 rorodo 阅读(293) 评论(0) 推荐(0)
类属性和方法,对象属性和方法。以及用闭包做的私有属性例子。
摘要:function Complex(real, imaginary) { this.x = real; // The real part of the number this.y = imaginary; // The imaginary part of the number } ;Complex.prototype.magnitude = function( ) { return Math.sqrt(this.x*this.x + this.y*this.y); };Complex.prototype.negative = function( ) { ... 阅读全文
posted @ 2012-07-17 15:53 rorodo 阅读(243) 评论(0) 推荐(0)
js闭包
摘要:uniqueID=function(){if(!arguments.callee.id) arguments.callee.id=0;return arguments.callee.id++;}uniqueID();uniqueID();uniqueID();alert(uniqueID.id);uniqueID.id=0;//设置uniqueID属性id为0.alert(uniqueID.id);//0实现一个函数,使用自己的属性来存储雍久值。但在函数外部,可以重设id为0.uniqueID=(function(){var id=0;return function(){return id++ 阅读全文
posted @ 2012-07-13 15:39 rorodo 阅读(218) 评论(0) 推荐(0)
函数运用,对象中的函数就是对象的方法。
摘要://函数add和substract.function add(x,y){return x+y;}function substract(x,y){return x-y}//operate函数调用“operator”参数传入的函数,比如add\abstract。function operate(operator,operatd1,operatd2){return operator(operatd1,operatd2);}operate(add,4,5);//调用add(4,5)函数。9operate(add,operate(add,5,1),operate(substract,4,2));//8/ 阅读全文
posted @ 2012-07-11 15:47 rorodo 阅读(279) 评论(0) 推荐(0)
7-11js问题!
摘要:case "object":n=flexisum.apply(this.element)://不懂什么意思。 阅读全文
posted @ 2012-07-11 14:34 rorodo 阅读(120) 评论(0) 推荐(0)