- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Lecture8Object-OrientedJavaScript全解
* * Most people are used to regular object-oriented programming where types are defined by classes, which are usually closed (you cannot change them dynamically), and where they serve as blueprints for all instances of the class. Classes can organize themselves in a hierarchy, where every child class inherits all the attributes of its ancestor classes. JavaScript works in an entirely different way. Everything is an object, and every object is defined by a constructor function and this constructor’s prototype. A prototype is basically a repository of things (mostly methods) that all objects produced by the constructor function share. * * * * * * * 载入时分支 var getXHR = function () { if (window.XMLHttpRequest) { return function () { // 返回一个标准的XHR实例 }; } else { return function () { // 返回一个浏览器的XHR实例 }; } }(); // 注意: 父对象触发自我调用 运行时替换 var documentListFactory = function () { var out = []; // 只是一个简单的数组 // 重写默认的.push()方法 out.push = function (document) { Atotype.push.call(out, { document : document, timestamp : new Date().getTime() }); }; return out; }; 总结 学习工具 Firebug 对象和函数 JavaScript != Java 对象字面量, 数组字面量, JSON 函数: 对象, 可调用, 返回值 构造函数和原型( Prototype) 构造函数 , 构造函数属性 内置构造函数 , 约定 原型, __proto__ 链 继承 通过复制, 原型的 多态 载入时分支, 运行时替换 练习 在Firebug控制台中用JavaScript编写代码定义Employee , Manager , 和Secretary 的类 每个Employee拥有名字和薪水 每个 Manager 都是 Employee, 并且管理一组其他的Employees 每个 Secretary 都是Employee, 并为Manager 工作 给这些类添加方法 每个Employee 有一个show()方法,以字符串的形式返回自己 的名字和薪水 每个 Manager 有一个 getInferiors()方法,返回他的下属 每个Secretary 有一个getSuperior()方法, 返回他的老板 尝试使用两种不同的继承方式, 复制和原型 进阶阅读 JavaScript介绍 /wiki/JavaScript W3Schools JavaScript 教程/js/default.asp Mozilla Developer Center JavaScript 文档/en/javascript JavaScript面向对象编程 ,作者Mike Koss /jscript/object.htm JavaScript面向对象编程 Part 1 /article/oriented-programming-1 JavaScript面向对象编程 Part 2 /article/oriented-programming-2 Thank you! * * * * * * * * * * * * * * * * * * * * * * * * * * Web 2.0 P
您可能关注的文档
最近下载
- 小学体育三年级下册全册教案表格式小学体育三年级下册全册教案表格式.doc VIP
- (2025)冠脉介入培训试题答案.docx VIP
- 毛利人的传统文化.pptx VIP
- 新西兰毛利文化课件.pptx VIP
- 固体物理学 -课件(3.1.1)--第三单元课件.pdf VIP
- 小学三年级上册体育计划及教案(全册)(表格式107页).doc VIP
- Dell戴尔Dell 32 Plus 4K QD-OLED显示器 - S3225QC用户指南.pdf
- 部编版小学二年级下册道德与法治第三单元《绿色小卫士》教材解读.pdf VIP
- 遗失补办户口本授权委托书.doc VIP
- 2020年自考《播音与主持创作基础》练习试题及答案.doc VIP
文档评论(0)