Your SlideShare is downloading. ×
Java Script对象模型
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Java Script对象模型

1,220
views

Published on


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,220
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
24
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Transcript

    • 1. 范武
    • 2. JavaScript 对象
      • (nearly) Everything is a Hash
      • There Are No Classes in JavaScript
      • Functions Are Objects(values)
    • 3. 对象和函数
    • 4. 类型识别
      • typeof
      • Instanceof
      • Constructor
        • this.prototype = {constructor : this};
    • 5. 对象构造过程
      • Instead, I think of constructors as being like “cookie cutters” for objects. When a function is used with the new operator, it’s called in a special way: instead of executing the function normally and returning a result, a new blank object is created. Then, when the function is called, its this operator points to that new blank object. Additionally, the constructor property of the blank object is set to point to the constructor function itself.
    • 6. prototype
      • Every function has a prototype property and it contains an object.
        • only function naturelly have a prototype property, by default it is an object.
      • The difference between own properties and properties of the prototype
      • __proto__, the secret link every object keeps to its prototype
      • Methods such as isPrototypeOf(), hasOwnProperty(), and propertyIsEnumerable()
      • How to enhance built-in objects, such as arrays or strings
    • 7. Prototype
      • 构造函数 在构造对象时,会在对象内生成一个“隐藏”的 __proto__ 属性指向 构造函数 的 prototype 对象。
      • 在对象查找属性时,先在对象的上下文 ( Context) 中查找,如果查找不到再到 __proto__ 中进行查找,并一直递归下去。
    • 8. Prototype Chain
    • 9. Prototypal-inheritance
      • 对象的构造函数可以从其他对象中继承方法,它创建一个 原型 对象后,所有其他的新对象都可以基于这个原型对象来构建。  
      • 整个过程都是通过原型 属性 来实现的(每个函数都有这个属性)。原型式继承适用于单继承而非多继承。
      • 这种继承方式之所以特别难以掌握,是因为原型本身不会从其他原型或者构造函数中继承属性,而属性都是从实际对象那里继承过来的。
      • User.prototype = new Person();
      • User 是对 User 对象构造函数的引用。 new Person() 使用 Person 构造函数构造一个新的 Person 对象,然后把 User 构造函数的原型置为这个操作的结果。也就是说当你 new User() 时,得到新的 User 对象都会带有 Person 对象所有的方法,如同通过操作 new Person() 得到一样。
      •  
      • 构造函数的 prototype 储存的是一个对象,当你改变这个对象的属性时,所有根据这个构造函数生成的对象中“继承”自 prototype 的属性都会发生改变。
    • 10. class type inheritance
      • 标准 class 的声明形式
      • 注意事项
      • Class 的几种封装
    • 11. Class type inheritance - prototype
      • Class.create 的使用
        • Old type
        • New type
      • Class.create 的实现
    • 12. Class type inheritance - mootools
      • Usage:
        • Extends
        • Implements
      • Implementation
        • Klass
        • mutators
    • 13. Class type inheritance - Dojo
      • Usage
        • declare
      • implementation
    • 14. namespace
      • 使用 namespace 封装代码
      • Namespace 声明工具
    • 15. module
      • Dogulas Crockford
      • YUI
      • Closure pattern
    • 16. Mix-in
      • 来源于 Python, Ruby
      • 将模块 (module) 中的变量或函数“混入”到类中
      • 本质上就是代码拷贝
      • 示例: Enumerable
    • 17. Prototypal
      • No class, just object
      • No inheritance, just prototype and mix-in
      • Mochikit
    • 18. Functional style
      • Oliver Steele – functional.js
      • Eugene Lazutkin - Dojo
      • 2D 3D 图形计算
    • 19.  
    • 20. Q1:
      • function f1(){ return 1;}
      • var f2 = function(){return 2;};
      • var f3 = new Function("return 3; ");
    • 21. Q2
      • var func1 = function(){
      • this.member_function = function(){
      • //.....
      • };
      • }
      • var func2 = function(){
      • }
      • func2.prototype.memeber_function = function(){
      • //...
      • }
    • 22. Q3
      • 如果模仿 java 的 package
      • Package
      • import
    • 23. Q4
      • Mix-in 的意义
      • 是否需要对 mix-in 添加类型识别
    • 24. Q5
      • What is this
      • Where is this
      • Bind this