javascript prototype
下面都是个人理解以及查找的网上的资料,如有不对的地方请指正
prototype
prototype在这里是原型的意思,不是指那个框架...
每个函数就是一个对象(Function),当函数被解析后会添加一个prototype的对象,然后prototype会添加一个constructor的属性
它指向那个函数的
比如定义一个function test(){}
它会自动添加一个prototype ; 即test.prototype={}
然后 prototype会自动添加一个test.prototype.constructor =test 它是指想函数本身的
可以测试一下 例子如下
function test(){
alert('a');
}
alert(test.prototype); //可以看出是obj
test.prototype.constructor(); //可以看出是执行了test
一个类,如何实例化成一个对象了,类里面的prototype里的属性又是怎么成为实例里面的属性的了
这里不得不说一下new 的过程
大概可以分成3步
这个例子可真好呀 哈哈
<1> var p={}; 也就是说,初始化一个对象p。
<2> p.__proto__=Person.prototype;
<3> Person.call(p);也就是说构造p,也可以称之为初始化p。
别人给的一个new的过程
/*
new操作原理(spiderMonkey引擎下)
*/
var a = function(sA,sH){
var x = "x";
this.a = sA;
this.h = sH;
this.say = function(){alert(this.a+','+x)}
}
a.prototype.hi = function(){alert(this.h)}
var createInstance = function(source){
var p = {}
var args = Array.prototype.slice.call(arguments,1);
source.apply(p,args);
p.__proto__ = source.prototype;
return p;
}
var A = createInstance(a,"A","hi A");
A.say();
A.hi();
如一个类 ,new 之后的对象如下
function test(){
this.name="taozi";
}
test.prototype={
sex : "nan"
}
var ss = new test();
/*
ss就相当于
{
name : "nan",
__proto__ : {sex : "nan"}
}
*/
//可以测试一下
alert('-----------我是华丽的分割线');
alert(ss.__proto__ === test.prototype); //记得在firefox下测试 ie下无法访问到__proto__ 可以看到弹出来的是true
__proto__这个也得介绍一下,它是个好东西.....
每个对象在初始化的时候都会有这么一个属性;
如: (请在firefox下测试)
var test ={};
alert(test.__proto__); //可以看但弹出的是obj
当有一个对象 假如是test ;查找他的a属
相关文档:
下面都是个人理解以及查找的网上的资料,如有不对的地方请指正
This
this 始终指向调用它的对象 ,都没有对象调用时就指向window
另外就是this一般都是在function中,当不在function中的时候 一定是指向window的.
var a ='a';
alert(this.a); //出来的是a
alert(this.b); //undefined 因为还没定义 ......
一、概述
考虑Html本身不带定时刷新页面的控件,且不考虑使用第三方控件;因此考虑使用Javascript中的setTimeout+xmlhttp来实现定时更新页面中部分内容,此实现在IE6.0及以上版本测试通过,其他浏览器暂时未测试过。
二、功能及特点
1、Javascript通过Microsoft的MSXML对象,动态获取后台数据库数据;
&n ......
• 小写金额与大写金额联动
<mce:script language="JavaScript"><!--
function daxie()
{
this.values = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
this.digits = ["", "拾", "佰", "仟"];
}
function daxie.prototype.getdx(num)
{
if(isNaN(num)) return "";
var number = ......
/*样式*/
<style type="text/css">
td{font-size:12px;}
.item{text-decoration:none;width:100%;height:100%; line-height:22px;cursor:default;color:Black;vertical-align:middle}
.staticTab{cursor:default;height:22px}
  ......