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

javascript 中的继承方法

1.可以通过prototype属性,实现继承方法的方式,这种方式就是java语言中继承的变换形式。
 // Create the constructor for a Person object
function Person( name ) {
    this.name = name;
}
// Add a new method to the Person object
Person.prototype.getName = function() {
    return this.name;
};
Person.prototype.setName = function(name) {
    this.name = name;
};
// Create a new User object constructor
function User( name, password ) {
    // Notice that this does not support graceful overloading/inheritance
    // e.g. being able to call the super class constructor
    this.name = name;
    this.password = password;
};
// The User object inherits all of the Person object's methods
User.prototype = new Person();
2.通过自己写继承函数,实现继承,下面这段代码也很好,值得一看
// A simple helper that allows you to bind new functions to the
// prototype of an object
Function.prototype.method = function(name, func) {
    this.prototype[name] = func;
    return this;
};
// A (rather complex) function that allows you to gracefully inherit
// functions from other objects and be able to still call the  'parent'
// object's function
Function.method('inherits', function(parent) {
    // Keep track of how many parent-levels deep we are
    var depth = 0;
    // Inherit the parent's methods
    var proto = this.prototype = new parent();
    // Create a new 'priveledged' function called 'uber', that when called
    // executes any function that has been written over in the inheritance
    this.method('uber', function uber(name) {
        var func; // The function to be execute
        var ret; // The return value of the function
 &n


相关文档:

利用javascript验证邮箱地址是否合法

源代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>验证邮箱地址合法性</title>
    <sc ......

javascript编写web组件:多级菜单

    在web上编写菜单一直是比较头疼的事情,要是有个类直接套用就好了,最近又要做网站了,烦人,要求做的还是多级菜单,唉,废话少说,遇到问题就要解决啊,看代码:
   function is(e, handler) {  
    if (e.type != 'mouseout' && e.type != 'mouseover ......

JavaScript实际应用:对层的控制

层的开发在实际应用中比较重要,比如漂浮广告等等,我这里简单探讨一下。
1.  控制层的显示或隐藏
两种办法,其实都是控制样式的。
办法一:控制 display 属性
<script language="javascript">
function show(status)
{
          document.getElemen ......

[JavaScript]类之二

javascript 类定义4种方法
Java代码
/*  
   工厂方式--- 创建并返回特定类型的对象的 工厂函数 ( factory function )   
*/  
    
  
function createCar(color,doors,mpg){   
   ......

[JavaScript]类之三


详解javascript类继承机制的原理
目前 javascript的实现继承方式并不是通过“extend”关键字来实现的,而是通过constructor function和prototype属性来实现继承。首先我们创建一个animal类
js 代码
 
 var animal = function(){  //这就是constructor function 了&nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号