javascript部分知识点

1:script放置位置:
a:<title></title>之后
b:<body>之后
c:<body>中的<div></div>之后
这说明:javascript可以在html页面当中的任何位置来进行调用,但是他们还是一个整体,是相互联系,相互影响的。

2:如何把共享的代码比如方法之类的放在代码段中让大家共享,节省内存空间。
办法:prototype方法
原因:prototype其实是函数里的一个属性
eg:function TV(color,size,brand){
this.color=color;
this.size=size;
this.brand=brand;
this.play=function(){ alert("我在玩游戏");}
}
这样改写之后就不用每次调用都会创建look方法了,已经放在共享区
TV.prototype.look=function(){
alert("看电视");
}
注意prototype只能共享属性和方法,不能共享对象。
3:原型继承:prototype继承
eg:function person(){this.name="aa"}
function student(){}
继承时这样写即可:student.prototype=new person()
然后就可以使用了,eg:var zhagnsan=new student();
4:继承方式:对象冒充
eg:function person(){this.name="aa"}
继承时这样写即可:function student(){window.person.call(this)}window可省
此时即可var stu=new student()了
5:对象冒充的形式:让对象1的方法冒充成对象2的方法。
A.call
obj1.fun.call(obj2,参数1......)
B.apply
obj1.fun.call(obj2,[参数1,参数2....])
6:继承顺序:

原文地址:https://www.cnblogs.com/m-xy/p/3722783.html