类的定义有3种基本方法:
1、创建并能返回特定类型的对象的函数(工厂函数)如:
function wu()
{
var w=new object;
o.a=1;
return o;
}用这种方式创建对象:var u=wu();
2、创建构造函数,用new实例化例如:
function wu()
{this.a=1;}
用这种方式创建对象: var u=new wu();
3、原型方式,利用对象prototype的属性例如:
function wu()
{}
wu.prototype.a=1;
用这种方式创建对象 var u=new wu();
类的继承
类的继承有两种
对象冒充基本原理:构造函数使用this关键字给所有的属性和方法赋值(构造函数仅仅是赋值函数),所以可以利用一种方式,在类内部直接运行赋值函数,把this关键字传递给新类:
如:
var a=function()
{
this.a=1;
this.b=1;
alert(this);
}
var b=function()
{
this.aa=a;//对a中的this 进行转换,同样的方式还有
this.aa();
delete this.aa;//要把这个中间方法删除掉,否则会在以后的操作中覆盖原来类的方法
//或者
a.call(this,arg1,arg2);
//或者
a.apply(this,[args]);
}
var ob=new b();
原型链:
基本原理:关于原型链,详见(http://www.javaeye ......
自从学习JavaScript以来,一直对函数闭包不是太理解。知道大概是什么个意思,但是要将一个不会的人教会还真不行。总之就是不能彻底的理解。
今天看到的这篇文章感觉不错,和大家分享一下。
http://www.felixwoo.com/archives/247 ......
对象属性:
document.title //设置文档标题等价于HTML的<title>标签
document.bgColor //设置页面背景色
document.fgColor //设置前景色(文本颜色)
document.linkColor //未点击过的链接颜色
document.alinkColor //激活链接(焦点在此链接上)的颜色
document.vlinkColor //已点击过的链接颜色
document.URL //设置URL属性从而在同一窗口打开另一网页
document.fileCreatedDate //文件建立日期,只读属性
......
Definition and Usage
定义与用法The constructor property is a reference to the function that created an object.
constructor属性是所建立对象的函数参考Syntax
语法object.constructor
Example 1
举例
In this example we will show how to use the constructor property:
在这个举例中我们将展示如何使用constructor属性:
<script type="text/javascript">
var test=new Array()
if (test.constructor==Array)
{document.write("This is an Array")}
if (test.constructor==Boolean)
{document.write("This is a Boolean")}
if (test.constructor==Date)
{document.write("This is a Date")}
if (test.constructor==String)
{document.write("This is a String")}
</script>
The output of the code above will be:
输出结果为:
This is an Array
Example 2
举例2
In this example we will show how to use the constructor property:
在这个举例中我们将展示如何使用constructor属性:
<script type="text/javascript">
function employee(name,jobtitle,born)
{
this.name=name
this.jobtitle=jobtitle
this.bo ......
1.document.write( " "); 输出语句
2.JS中的注释为//
3.传统的HTML文档顺序是:document- >html- >(head,body)
4.一个浏览器窗口中的DOM顺序是:window- >(navigator,screen,history,location,document)
5.得到表单中元素的名称和值:document.getElementById( "表单中元素的ID號 ").name(或value)
6.一个小写转大写的JS: document.getElementById( "output ").value = document.getElementById( "input ").value.toUpperCase();
7.JS中的值类型:String,Number,Boolean,Null,Object,Function
8.JS中的字符型转换成数值型:parseInt(),parseFloat()
9.JS中的数字转换成字符型:( " " 变量)
10.JS中的取字符串长度是:(length)
11.JS中的字符与字符相连接使用號.
12.JS中的比较操作符有:==等于,!=不等于, >, >=, <. <=
13.JS中声明变量使用:var来进行声明
14.JS中的判定语句结构:if(condition){}else{}
15.JS中的循环结构:for([initial expression];[condition];[upadte expression]) {inside loop}
16.循环中止的命令是:break
17.JS中的函数定义:function functionName([parameter],...){statement[s]}
18.当文件中出现多个form表 ......
在JavaScript中可以创建三种消息框:警告框、确认框、提示框
警告框经常用于确保用户可以得到某些信息。当警告框出现后,用户需要点击确定按钮才能继续进行操作。
语法:
alert("文本")
确认框用于使用户可以验证或者接受某些信息。当确认框出现后,用户需要点击确定或者取消按钮才能继续进行操作。如果用户点击确认,那么返回值为 true。如果用户点击取消,那么返回值为 false。当需要换行时加上"/n"
语法:
confirm("文本")
提示框经常用于提示用户在进入页面前输入某个值。当提示框出现后,用户需要输入某个值,然后点击确认或取消按钮才能继续操纵。如果用户点击确认,那么返回值为输入的值。如果用户点击取消,那么返回值为 null。
语法:
prompt("文本","默认值")
......