易截截图软件、单文件、免安装、纯绿色、仅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字符串函数大全


JS自带函数
concat
将两个或多个字符的文本组合起来,返回一个新的字符串。
var a = "hello";
var b = ",world";
var c = a.concat(b);
alert(c);
//c = "hello,world"
indexOf
返回字符串中一个子串第一处出现的索引(从左到右搜索)。如果没有匹配项,返回 -1 。
var index1 = a.indexOf("l");
//index1 = 2 ......

JavaScript打开新窗口


语法
oNewWindow = window.open( [sURL] [, sName] [, sFeatures] )
sURL 可选. URL 字符串 . 如果URL为空, 将以about:blank打开.
sName 可选. 字符串 描述打开窗口的名字(name). 可以做为form 和 a 标签的TARGET属性值 .
sFeatures 可选. 字符串 格式如"fullscreen=yes,toolbar=yes".channelmode = { yes | no | ......

JavaScript prototype 属性

定义与用法
The prototype property allows you to add properties and methods to an
object.
prototype属性允许你向一个对象添加属性和方法
Syntax
语法
object.prototype.name=value
Example 1
实例
In this example we will show how to use the prototype property to add a
property to an object:
在下 ......

[JavaScript]类之一

一个简单的javascript类定义例子
     涵盖了javascript公有成员定义、私有成员定义、特权方法定义的简单示例
Java代码
<script>     
    //定义一个javascript类   
    function JsClass(privateParam/*&n ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号