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

JavaScript 继承 myhere

// 学习要想拷贝那么快就好了
//
// JavaScript 的继承是基于 prototype 的,每个对象的 prototype 是保存在对象的 __proto__ 属性中的,这个属性是内部(internal)的属性( 惯例是内部的或者隐藏的属性以 _ 开头)
// A prototype-based language has the notion of a prototypical object, an object used as a template from which to get the initial properties for a new object.
//
/**
* Property lookup in Javascript looks within an object's own properties and,
* if the property name is not found, it looks within the special object property __proto__.
* This continues recursively; the process is called "lookup in the prototype chain".
* The special property __proto__ is set when an object is constructed;
* it is set to the value of the constructor's prototype property.
* So the expression new Foo() creates an object with __proto__ == Foo.prototype.
* Consequently, changes to the properties of Foo.prototype alters the property lookup for all objects that were created by new Foo().
*/
// 给对象的原型增加成员会立即在该对象中可见
function Base(){
this.name = 'myhere';
}
function Sub(){
this.age = 23;
}
Sub.prototype = new Base(); // 给原型赋值为一个==对象==。

var me = new Sub();

// 创建对象后给原型增加 sex 属性,该属性立即在对象中可见
Base.prototype.sex = 'male';

var str = '';
str += me.name + me.age + me.sex;
document.write( str); // myhere23male
/**
* 说明:
* 对于这种继承,在频繁修改原型的情况下就变得混乱了
*/
//
/**
* 另一种继承方法
*/
function Base(){
this.name = 'myhere';
}
// 并没有将 Sub 的原型赋值为 Base,只是在 Sub 中调用 Base 函数
function Sub(){
this.age = 23;
Base.call( this); // 只是将一部分初始化交给 Base 函数,并没有操作 prototype
}

var me = new Sub();

Base.prototype.sex = 'male'; // 修改 Base 不会影响 Sub 的对象,因为 Base 并不是 Sub 的原型
// 如果将这个增加 sex 的语句放到 Sub 定义前,在 me 中也得不到 sex 属性,
// 因为 Base.call() 只是调用 Base 函数而已

var str = '';
str += me.name + m


相关文档:

Javascript 字符串 substring 与 substr 区别

stringObject.substring(start,end);
函数方法将返回一个包含从 start 到最后(不包含 end )的子字符串的字符串.
start     必需。一个非负的整数,规定要提取的子串的第一个字符在 stringObject 中的位置.
stop     可选。一个非负的整数,比要提取的子串的最后一个字符在 stringObject ......

Javascript之浏览器对象


浏览器对象
 
 
浏览器对象就是网页和浏览器本身各种实体元素在JavaScript程序中的体现。这样的浏览器对象主要包括以下几个
●  Navigator:管理者当前使用浏览器的版本号、运行的平台以及浏览器使用的语言等信息。
●  Windows对象:处于整个从属表的最顶级位置。每一个这样的对象代表一个浏览 ......

常用正则表达式,常用表单验证javascript代码

function f_MobilCheck(as_SourceString)
{
 if(as_SourceString.match(/^13[0-9]{9}$/g)) return true;  //手机号为13开头的11位数字
 else if(as_SourceString.match(/^[0]{1}[0-9]{2,3}[2-8]{1}[0-9]{5,7}$/g)) return true;  //小灵通为0开头的3-4位的区号+不以1和9开头的6-8位数字
 retur ......

javascript 学习笔记(1)

1. javascript 是区分大小写的,包括变量、函数名等等。
2. javascript 中的变量是弱类型的,定义变量时只用 var 运算符。
var test1 = "hi";
或者
var test1 = "hi",test2 = "hello";
或者(可以是不同的类型)
var test1 = "hi",test2 = 12;
或者(可以不用初始化)
var test1;
3. javascript 每条语句的结尾&ldqu ......

JavaScript prototype的体会


    在JavaScript中原型就相当于java中的类定义,每个JavaScript实例对象都会包含原型中定义的属性与方法。
   在编写构造函数时,可以使用原型对象(它本身是所有构造函数的一个属性)的属性来创建继承属性和共享方法。
原型属性和方法将按引用复制给类中的每个对象,因此它们都具有相同的值 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号