-
-
functionClassA(id){
-
this.id=id;
-
this.sayId=function(){
-
alert(this.id);
- };
- }
-
-
functionClassB(id,name){
-
this.newMethod=ClassA;
-
this.newMethod(id);
-
deletethis.newMethod;
-
-
this.name=name;
-
this.sayName=function(){
-
alert(this.name);
- };
- }
-
-
functionClassB(id,name){
-
ClassA.call(this,id);
-
-
this.name=name;
-
this.sayName=function(){
-
alert(this.name);
- };
- }
-
-
functionClassB(id,name){
-
ClassA.apply(this,newArray(id));
-
-
this.name=name;
-
this.sayName=function(){
-
alert(this.name);
- };
- }
-
-
functionClassA(id){
-
this.id=id;
- }
-
ClassA.prototype.sayId=function(){
-
alert(this.id);
- };
-
functionClassB(id,name){
-
ClassA.call(this,id);
-
this.name=name;
- }
-
ClassB.prototype=newClassA();
-
ClassB.prototype.sayName=function(){
-
alert(this.name);
- }
对象能够执行prototype 属性定义的方法,是因为用构造方法生成的对象和构造方法之间有紧密联系,对象寻找属性时,如果自己没有这个属性,会在构造方法的propotype所指向/引用的对象中找,看能否找到同名属性,如果找到,就会读取它的值并返回.(这个过程会持续向上,直到持续到Object对象为止,即所谓原型方式的继承).
-
varo={};
-
o.eat=function(){return"3432";};
-
o.pass=function(text){this.name=text;};
-
varHuman=newFunction();
- Human.prototype=o;
-
vartt=newHuman();
使用prototype与apply实现类继承的模拟。用prototype把父类的公有方法与公有变量加入到子类中去。在子类构造方法中,用apply执行父类的构造方法。
-
functionParent()
-
{
-
this.pname="parentName";
-
this.say=function(){alert(this.pname)};
-
this.tell=function(){alert(this.pname+"tell")};
- }
-
functionSon()
- {
-
-
Son.prototype=newParent();
-
Parent.apply(this);
-
this.sname="sonName";
-
this.say=function(){alert(this.sname)};
-
this.talk=function(){alert(this.sname+"talk")};
- }
用js实现自已定义的类体系
-
varPerson={
-
Create:function(name,age){
-
this.name=name;
-
this.age=age;
- },
-
SayHello:function(){
-
alert("Hello,I'm"+this.name);
- },
-
HowOld:function(){
-
alert(this.name+"is"+this.age+"yearsold.");
- }
- };
-
-
functionFun(){Person.Create("dd","ss");};
-
Fun.prototype=Person;
-
-
-
-
-
varp=newFun();
-
p.SayHello();
新的基本对象创建
-
varTObject={
-
IsA:function(aType)
- {
-
varself=this;
-
if(self.Type==aType)
-
returntrue;
- self=self.Type;
-
while(self)
- {
-
if(self.ParentType==aType)
-
returntrue;
- self=self.ParentType;
- };
-
returnfalse;
- }
- };
-
functionClass(aBaseClass,aClassDefine)
- {
-
functionclass_()
- {
-
this.ParentType=aBaseClass;
-
for(varmemberinaClassDefine)
-
this[member]=aClassDefine[member];
- };
- class_.prototype=aBaseClass;
-
returnnewclass_();
- };
-
functionNew(aClass,aParams)
- {
-
functionnew_()
- {
-
this.Type=aClass;
-
if(aClass.create)
-
aClass.create.apply(this,aParams);
- };
- new_.prototype=aClass;
-
returnnewnew_();
- };
- Person2=Class(TObject,{
-
T2:'sdfsd',
-
create:function(name,age)
- {
-
this.name=name;
-
this.age=age;
- },
-
sayHello:function()
- {
-
alert(this.name+''+this.age);
- }
- });
分享到:
相关推荐
通用方法创建XmlHttp对象,处理异步请求,而特定页面的方法则负责更新内容。考虑到不同浏览器对XMLHttpRequest对象的实现差异,提供了针对IE和非IE浏览器(如Firefox、Netscape、Safari)的实现。此外,回调函数用于...
【全栈开放2021年课程返回资料库】是一个针对2021年度全栈开发学习者的重要资源...同时,这也为独立学习者提供了一个自我检验和提升的平台,他们可以参照这些资料进行自我学习,或者查找在实际开发中遇到的问题的答案。
)和指定宽高(width和height),来创建一个参照环境,内部元素的居中就是相对于这个容器进行计算的。背景色的设置(background)则是为了增强视觉效果,便于观察元素是否正确居中。 而JavaScript代码部分则负责...
示例代码中封装了一个animationShow方法,此方法用于创建动画。该方法接收卡片对象、透明度、延迟时间以及移动方向作为参数,通过调整Animation对象的状态和属性,生成特定的动画效果。方法调用后,动画队列会被导出...
4. **ORM(对象关系映射)**:如Sequelize或TypeORM,可以将JavaScript对象与数据库表格映射,简化数据库操作,提高开发效率。 5. **安全措施**:包括密码哈希存储、防止SQL注入、CSRF防护等,确保用户数据的安全。...
9. **持续集成/持续部署(CI/CD)**:项目可能使用Jenkins、Travis CI或GitHub Actions等工具实现自动化构建和部署,确保代码的快速迭代和稳定运行。 10. **文档和API文档**:良好的开源项目通常会提供详细的README...