易截截图软件、单文件、免安装、纯绿色、仅160KB

javascript的函数调用继承实现

看到一篇入门的JS继承文章,转载下
原地址:http://sdcyst.javaeye.com/blog/288813
类变量/类方法/实例变量/实例方法
先补充一下以前写过的方法:
在javascript中,所有的方法都有一个call方法和apply方法.这两个方法可以模拟对象调用方法.它的第一个参数是对象,后面的
参数表示对象调用这个方法时的参数(ECMAScript specifies two methods that are defined for all functions, call()
and apply(). These methods allow you to invoke a function as if it were a method of some other object. The first
argument to both call() and apply() is the object on which the function is to be invoked; this argument becomes
the value of the this keyword within the body of the function. Any remaining arguments to call() are the values
that are passed to the function that is invoked).比如我们定义了一个方法f(),然后调用下面的语句:
f.call(o, 1, 2);
作用就相当于
o.m = f;
o.m(1,2);
delete o.m;
举个例子:
Js代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://www.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" src="http://www.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=function%20Person(name%2Cage)%20%7B%20%20%2F%2F%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%0A%20%20%20%20this.name%20%3D%20name%3B%0A%20%20%20%20this.age%20%3D%20age%3B%0A%7D%0Avar%20o%20%3D%20new%20Object()%3B%20%20%20%2F%2F%E7%A9%BA%E5%AF%B9%E8%B1%A1%0Aalert(o.name%20%2B%20%22_%22%20%2B%20o.age)%3B%20%2F%2Fundefined_undefined%0A%0APerson.call(o%2C%22sdcyst%22%2C18)%3B%20%2F%2F%E7%9B%B8%E5%BD%93%E4%BA%8E%E8%B0%83%E7%94%A8%3Ao.Person(%22sdcyst%22%2C18)%0Aalert(o.name%20%2B%20%22_%22%20%2B%20o.age)%3B%20%2F%2Fsdcyst_18%0A%0APerson.apply(o%2C%5B%22name%22%2C89%5D)%3B%2F%2Fapply%E6%96%B9%E6%B3%95%E4%BD%9C%E7%94%A8%E5%90%8Ccall%2C%E4%B8%8D%E5%90%8C%E4%B9%8B%E5%A4%84%E5%9C%A8%E4%BA%8E%E4%BC%A0%E9%80%92%E5%8F%82%E6%95%B0%E7%9A%84%E5%BD%A2%E5%BC%8F%E6%98%AF%E7%94%A8%E6%95%B0%E7%BB%84%E6%9D%A5%E4%BC%A0%E9%80%92%0Aalert(o.name%20%2B%20%22_%22%20%2B%20o.age)%3B%20%2F%2Fname_89" qua


相关文档:

javascript写类方式之三

取前面两种的优点:
a、用构造函数来定义类属性(字段)
b、用原型方式来定义类的方法。
就有了第三种方式。这种方式貌似采用的人较多。
3、综合构造函数/原型
/**
* Person类:定义一个人,有个属性name,和一个getName方法
* @param {String} name
*/
function Person(name) {
this.name = name;
}
Pers ......

javascript写类方式之四

通过前面几篇得知javascript写类无非基于构造函数
和原型
。既然这样,我们写个工具函数来写类。
/**
* $class 写类工具函数之一
* @param {Object} constructor
* @param {Object} prototype
*/
function $class(constructor,prototype) {
var c = constructor || function(){};
var p = prototype || {}; ......

通过javascript获得url参数

页面提交数据一般有两种方法:get,post。post就是所谓的form提交,使用视图;get是通过url提交。
Get方法一般用后台代码(如asp,asp.net)获得参数,代码很简单:Request.QueryString["id"];即可获取。 
有些时候需要直接在前台获取url参数,要用到javascript,js没有直接获取url参数的方法,那么,我们如何通过js ......

公历转换农历的算法(JavaScript)

很经典的一个算法,学习…ing… :
<!--  中国农历开始  -->
<SCRIPT language=JavaScript>
<!--
var lunarInfo=new Array(
0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,
0x04ae0,0x0a5b6,0x0a4d0,0x0d25 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号