标签:doctype distinct 继承 turn return htm 实现 doc ret
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h2>js中的继承</h2> </body> <script> function extend(distinct,src) { if(typeof src === ‘object‘){ for(var name in src){ distinct.prototype[name] = src[name]; } }else{ for(var name in src.prototype){ distinct.prototype[name] = src.prototype[name]; } } return distinct; } //对象F,子对象-基类 function F() {} F.prototype.name = ‘F‘;//属性name var f = { age:7, sex:‘aa‘ }; function P() { } P.prototype.title = ‘T‘; var SuperF = extend(F,f); SuperF = extend(SuperF,P); var superF = new SuperF(); alert(superF.name); alert(superF.age); alert(superF.title) </script> </html>
标签:doctype distinct 继承 turn return htm 实现 doc ret
原文地址:http://www.cnblogs.com/lliule/p/7880469.html