JS内置函数应用Word文件下载.docx

上传人:b****5 文档编号:19190314 上传时间:2023-01-04 格式:DOCX 页数:21 大小:18.59KB
下载 相关 举报
JS内置函数应用Word文件下载.docx_第1页
第1页 / 共21页
JS内置函数应用Word文件下载.docx_第2页
第2页 / 共21页
JS内置函数应用Word文件下载.docx_第3页
第3页 / 共21页
JS内置函数应用Word文件下载.docx_第4页
第4页 / 共21页
JS内置函数应用Word文件下载.docx_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

JS内置函数应用Word文件下载.docx

《JS内置函数应用Word文件下载.docx》由会员分享,可在线阅读,更多相关《JS内置函数应用Word文件下载.docx(21页珍藏版)》请在冰豆网上搜索。

JS内置函数应用Word文件下载.docx

)).join('

);

}

console.log('

maizi'

.reverse());

king'

//检测方法是否存在,不存在则扩展

if(!

Array.prototype.inArray){

Array.prototype.inArray=function(needle){

for(vari=0,len=this.length;

i<

len;

i++){

if(this[i]==needle){

returntrue;

}

}

returnfalse;

}

vararr=['

a'

'

b'

c'

d'

];

console.log(arr.inArray('

));

console.log(arr.inArray("

C"

functionPerson(){

this.mouth=true;

varp1=newPerson();

varp2=newPerson();

Person.prototype.say=function(){

return'

hello'

;

console.log(p1.say());

console.log(p2.say());

console.log(p1.constructor);

console.log(p1.constructor.prototype.constructor);

console.log(p1.constructor.prototype.mouth);

Person.prototype={

hair:

true,

face:

true

};

console.log(typeofp1.hair);

console.log(typeofp1.__proto__.say);

console.log(typeofp1.__proto__.hair);

varp3=newPerson();

console.log(typeofp3.__proto__.say);

console.log(typeofp3.__proto__.hair);

console.log(typeofp3.__proto__.face);

console.log(p3.constructor);

console.log(typeofp3.constructor.prototype.hair);

console.log(typeofp1.constructor.prototype.hair);

'

hair'

:

Person.prototype.constructor=Person;

varp4=newPerson();

console.log(p4.constructor);

console.log(typeofp4.constructor.prototype.hair);

2重置constructor

functionShape(){

this.name='

shape'

this.toString=function(){

returnthis.name;

}

functionTwoDShape(){

2Dshape'

functionTriangle(side,height){

triangle'

this.side=side;

this.height=height;

this.getArea=function(){

returnthis.side*this.height/2;

TwoDShape.prototype=newShape();

Triangle.prototype=newTwoDShape();

//重置constructor属性

TwoDShape.prototype.constructor=TwoDShape;

Triangle.prototype.constructor=Triangle;

varmyTriangle=newTriangle(5,10);

console.log(myTriangle.getArea());

console.log(myTriangle.toString());

console.log(myTriangle.constructor);

console.log(myTriangleinstanceofTriangle);

console.log(myTriangleinstanceofTwoDShape);

console.log(myTriangleinstanceofShape);

console.log(Shape.prototype.isPrototypeOf(myTriangle));

console.log(TwoDShape.prototype.isPrototypeOf(myTriangle));

console.log(Triangle.prototype.isPrototypeOf(myTriangle));

console.log(Object.prototype.isPrototypeOf(myTriangle));

console.log(String.prototype.isPrototypeOf(myTriangle));

vartd=newTwoDShape();

console.log(td.constructor);

console.log(td.toString());

vars=newShape();

console.log(s.constructor);

console.log(s.toString());

/script>

/body>

/html>

3Shape

//functionShape(){

//this.name='

//}

functionShape(){};

Shape.prototype.name='

Shape.prototype.toString=function(){

functionTwoDShape(){};

TwoDShape.prototype=newShape();

TwoDShape.prototype.constructor=TwoDShape;

TwoDShape.prototype.name='

2DShape'

functionTriangle(side,height){

this.side=side;

this.height=height;

Triangle.prototype=newTwoDShape();

Triangle.prototype.constructor=Triangle;

Triangle.prototype.name='

Triangle.prototype.getArea=function(){

varmyTriangle=newTriangle(5,10);

console.log(myTriangle.getArea());

console.log(myTriangle.toString());

console.log(myTriangle.hasOwnProperty('

side'

name'

console.log(myTriangleinstanceofTriangle);

console.log(myTriangleinstanceofTwoDShape);

console.log(myTriangleinstanceofShape);

console.log(Triangle.prototype.isPrototypeOf(myTriangle));

console.log(TwoDShape.prototype.isPrototypeOf(myTriangle));

console.log(Shape.prototype.isPrototypeOf(myTriangle));

console.log(Object.prototype.isPrototypeOf(myTriangle));

4字符串

TwoDShape.prototype=Shape.prototype;

Triangle.prototype=TwoDShape.prototype;

varmy=newTriangle(5,10);

console.log(my.getArea());

console.log(my.toString());

vars=newShape();

console.log(s.name);

5属性构造

Shape'

//声明临时构造器

varF=function(){};

F.prototype=Shape.prototype;

TwoDShape.prototype=newF();

F.prototype=TwoDShape.prototype;

Triangle.prototype=newF();

console.log(my.__proto__.__proto__.__proto__.constructor);

6uber

varresult=[];

if(this.constructor.uber){

result[result.length]=this.constructor.uber.toString();

result[result.length]=this.name;

returnresult.join('

'

TwoDShape.uber=Shape.prototype;

Triangle.uber=TwoDShape.prototype;

vartd=newTwoDShape();

console.log(td.toString());

7属性继承

functionextend(Child,Parent){

varF=function(){};

F.prototype=Parent.prototype;

Child.prototype=newF();

Child.prototype.constructor=Child;

Child.uber=Parent.prototype;

extend(TwoDShape,Shape);

extend(Triangle,TwoDShape);

8元素继承

functionextend1(Child,Parent){

varp=Parent.prototype;

varc=Child.prototype;

for(variinp){

c[i]=p[i];

c.uber=p;

varShape=function(){};

varTwoDShape=function(){};

vartd=ne

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1