JavaScriptOOP
来源:互联网 发布:智慧城市优化公共服务 编辑:程序博客网 时间:2024/06/06 19:50
function BaseConstructor1(name){ var varPriv01 = "hello varPriv01"; var funcPriv01 = function(){ alert("hello funcPriv01"); }; this.varPub01 = "hello varPriv01"; this.funcPub01 = function(){ alert("hello funPub01"+name); }}BaseConstructor1.staticFunc1 = function(){//静态方法 alert("hello staticFunc1");}function SubConstructor1(name){//继承 BaseConstructor1.call(this,name);}//---------------------原型继承------------------function Animal(){ this.eat = function(){ alert("animal eat!"); } this.move = function(){ alert("animal move!"); }}function Dog(){ this.bark = function(){ alert("Dog bark!"); } this.run = function () { alert("Dog run!"); }}
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title></head><script src="JSOOP.js"></script><body> <script> // var base001 = new BaseConstructor1("zhangsan"); // alert(base001.varPub01); // base001.funcPub01(); // // var sub01 = new SubConstructor1("lisi"); // sub01.funcPub01(); //BaseConstructor1.staticFunc1(); //alert(base001.constructor == BaseConstructor1); //Dog.prototype = new Animal(); //继承Animal Dog.prototype.eat = function(){//重写,使用prototype目的是节约内存 alert("parent eat!"); } var wangcai = new Dog();//容易消耗内存 // alert(wangcai.__proto__ === Dog.prototype); // alert(wangcai.__proto__.__proto__ === Animal.prototype); // wangcai.bark(); // wangcai.run(); wangcai.eat(); // wangcai.move(); //利用Json-》面向对象,只能当一个普通对象,不能new var monkey = { jump:function(){ alert("monkey jump"); }, run:function(){ alert("monkey run"); } } monkey.jump(); monkey.run(); var myDate = new Date(); myDate.setFullYear(2010,09,10); var date = new Date(); if(myDate > date){ alert("my"); } </script></body></html>
阅读全文
0 0
- javascriptOOP
- JavaScriptOOP
- mysql: error while loading shared libraries: libncursesw.so.5: cannot open shared object file: No su
- Effective TensorFlow Chapter 4: TensorFlow中的广播Broadcast机制
- 数列有序SUDTACM
- 哈理工oj 1180 报数【约瑟夫环】
- Spring
- JavaScriptOOP
- 版本说明
- 输出n范围内的素数(质数)
- 动态网页抓取Selenium的安装与使用
- JavaScript学习-面向对象与原型2
- python : bokeh 画基金净值线
- 代理模式
- request(十三)
- socket 有价值文章收集