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
相关文档:
文件内容如下:(两个文件glossy.js和glossy.html)
/********************************** glossy.js ***********************************/
/**
* glossy.js 1.31 (19-Jul-2007)
* (c) by Christian Effenberger
* All Rights Reserved
* Source: glossy.netzgesta.de
* Distrib ......
//把数据写入数据库
function
res(){
//获取输入值(myname和mymail是两个文本框的id)
var
uname = document.getElementById("myname"
).value;
var
umail = document.getElementById("mymail"
).value;
......
今天看jQuery的时候发现的书写形式原来没有见过 如下:
(function(){
statement
...
})();
不理解,后来上网查了一下,原来是javascript匿名函数的调用方式
http://zhidao.baidu.com/question/95789340.html
javascript 可以以下方式调用函数
声明
a = function(){};
调用
a();
可以理解为
(function(){ ......
标准的Web 组成应该包括3 部分:结构、行为和表现。这种思想最早在微软设计的
DHTML模型中初步提出来,但是很不规范,也不成系统。后来,W3C(World Wide Web
Consortium,万维网联盟)组织规范了Web 的构成。根据W3C 制订的标准,Web 标准不
是某一个标准,而是一系列标准的集合。完整的Web 应该由以下3 部分组成:
结 ......
一个简单的javascript类定义例子
涵盖了javascript公有成员定义、私有成员定义、特权方法定义的简单示例
Java代码
<script>
//定义一个javascript类
function JsClass(privateParam/*&n ......