常量:const ie中不支持,firefox支持
创建对象:function man( s,m)
{
This.s=s
This.m=m;
Function _call()
{alert}
This.call=_call;定义call方法
}
用new man()来创造对象
也可以
var object={m:’ja’,erafs:’jio’,call:function(){alert(1)}} object.call();
Var m=new Array();
M[1]=new Array();
Delete删除
Typeof:输出对象类型
Js全局函数
DecodeURI encodeuri escape eval :计算其中的值
isFinite isNaN parseFloat parseInt
Js核心对象
Array:可以添加删除替换元素排序 Boolean:转化成boolen值 Date Error EvalError Function Math :round()舍入到最近整数
object Number object eval error regexp syntaxerror RangeError Urierror String :转化成string值 new string是新建一个对象
全局函数:decodeuridecodeuricomponent encodeuri eval(解析javascript代码) escapeisfinite isNaN parseFloat parseint
Instanceof:判断是否同种对象
for in :可以打印对象或数组中的元素
for(var I in arr )
原型对象与继承
一个对象的原型是由构造该对象的构造函数来定义的,当使用原型对象时这个对象不会拥有原型对象的所有属性的方法,只有在使用时才会去原型对象中获取该对象的方法
可以动态的添加一个方法或属性
手机构造函数 function mobile()
{
This.color=”red”;
}
Var m=new mobile()
m.type”sfs”;节省空间,只为原型对象的属性和方法分配空间,mobile.prototype=newcamera(200px);否则要为每一个对象的属性和方法分配内存空间
var mm=new mobile()这样mm就有继承了canmera的特性
with语句
调用同一个对象多次时可用with
Eg:with(window.document)
{
Write(“1”);
Write(“2”);
}
为 Javascript 数组添加 insertAt 和 removeAt 方法 // 整理:http://www.CodeBit.cn Array.prototype.insertAt = function( index, value ) { var part1 = this.slice( 0, index); var part2 = this.slice( index); part1.push( value ); return( part1.concat( part2 ) ); }; Array.prototype.removeAt = function( index ) { var part1 = this.slice( 0, index ); var part2 = this.slice( index ); part1.pop(); return( part1.concat( part2 ) ); }
函数的定义方式:
1:function ss(参数)//没有定义返回类型
{
函数体
Return 返回值
}
2:new Function(参数1,参数2,语句块);没有函数体
函数中可以定义函数
Bom和dom
Bom:浏览器对象模型:
Window包括:history,frames,locationdocument screen等
Dom文档对象模型:不能获知screenhistory等,document.body….
In 运算符,判断某个属性是不是属于某个对象if(2 in arr)
Delete 对象等
String 对象:
Length,replace(a,b) charat 返回子字符串:substring,substr(通过起始位置和长度获得) slice 开始位置和结束位置间的字符串
toLowerCase().toUpperCase() a.conat(b,c)字符串连接 search(可以使用正则表达式)split分解
数组:使用join将数组转换成字符
添加数组元素,push ,unshift,splice
添加数组元素并返回数组 concat()
删除元素;pop shift ,slice
排序:sort 需要定义acs desc的函数才行
Reverse()