易截截图软件、单文件、免安装、纯绿色、仅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 ......

一个CSS+JavaScript编写的跑马灯程序

转自:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>图片跑马灯</title>
</head>
<body>
<div style="overflow:hidden; width:350px" id='div'>
<!-- 这里是第一个关键点,o ......

一些比较常见的Javascript框架简介

Dojo
      一个强大的面向对象javascript框架。
      主要由三大模块组成:Core、Dijit、DojoX。
      Core提供 Ajax,events,packaging,CSS-based querying,animations,JSON等相关操作API。
      Dijit ......

javascript小技巧

事件源对象
event.srcElement.tagName
event.srcElement.type 捕获释放
event.srcElement.setCapture(); 

event.srcElement.releaseCapture();  事件按键
event.keyCode
event.shiftKey

event.altKey
event.ctrlKey 事件返回值
event.returnValue 鼠标位置
event.x

event.y 窗体活动 ......

javascript对象之——内置对象“Math”

javascript对象之——内置对象“Math”
Math对象的一些方法能实现我们课本上的某些数学计算,比较常用的方法有如下几个:
一、Math.min()和Math.max(),分别返回参数中的最小和最大值
  例:
  alert(Math.min(1,2,3))  //输出 “1”
  alert(Math.max(1,2,3))  //输出 &ldq ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号