Master in javascript

1,705 views

Published on

deeply understand javascript.
http://neticy.com
http://www.joke4me.com

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,705
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
45
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • inheritance_apply_call_prototype.html
  • Master in javascript

    1. 1. JavaScript The World's Most Misunderstood Programming Language http://www.neticy.com http://www.joke4me.com robbin@gmail.com
    2. 2.  Basic knowledge  Dynamic language and functional language  JavaScript frameworks and applications  Debug and experiences of development
    3. 3. Basic Knowledge Literal notation Keywords Functions OOP DOM/HTML
    4. 4. Literal notation in languages A literal value is any part of a statement or expression that is to be used exactly as it is, rather than as a variable or a script element. You use literals to represent values in JavaScript. These are fixed values, not variables, that you literally provide in your script. This section describes the following types of literals: a. Array Literals b. Boolean Literals c. Floating-Point Literals d. Integers e. Object Literals (JSON) f. String Literals g. Regex Literals e.g. PHP/Java/C#: String, Integer, Boolean. Python: String, Dictionary , List, Tuple
    5. 5. typeof instanceof this in undefined /null delete try/catch/finally/throw || && Keywords
    6. 6. typeof " number" 、 "string" 、 "boolean" 、 "object" 、 "functio n" 、 "undefined “. If you just declare a variable, the default value of the variable is ‘undefined’. Always wrong if you are using an undefined variable. e.g. var s = s || {}; || Return the “true-like” variable, if both of them are true, return the first. ( Equal ? : ) && Return the “false-like” variable, if both of them are true, return the second.
    7. 7. instanceof Check if the instance is initialized from that function/class. Check if the prototype of some class/function is in the chain of some object. e.g. obj instanceof ClassA Since every object has a prototype chain, the operation of “instanceof” is to check if the ClassA’s prototype is in the chain of obj. So it could be “true” for many Class to one object.
    8. 8. Code snippet Every object has a constructor property. Every function/class has a prototype property which is an object, that is to say, it is an instance of function(class). Discussion: how to check if a variable is array?
    9. 9. in Return a boolean value which specifies if the first variable is a property/element of the second variable. console.log(‘2’ in [1,2,3]); console.log(‘join’ in [1,2,3]); console.log(‘top’ in window); undefined/null If you just declare a variable, there the value of the variable is ‘undefined’. Null is defined, the value of null is null. var d; if(d == undefined) console.log('fff');
    10. 10. delete Make a variable undefined. Delete a property of an object. var a = ‘tt’; delete a; try/catch/finally/throw try { aaa ;} catch(e) { console.log(e); }finally { console.log('ff');} It is not a good idea to hide an error only if you know what you are doing. throw Raise an exception.
    11. 11. this Dynamic language / Lazy evaluation “this” means what this is. Compare the differences of “this” in JavaScript/PHP/C# Change ‘this’ via “apply” and “call” functions. More detail will be the code analysis.
    12. 12. Trivial Code Snippet
    13. 13. Functions Execute function setTimeout/setInterval eval call/apply
    14. 14. Execute function call/apply
    15. 15. setTimeout/setInterval Mutil threads simulation in JavaScript. Animate effect in JavaScript.
    16. 16. eval
    17. 17. apply/call Specify a new current instance as the ‘this’ object. The difference of them is the arguments. {prototype library source code} bind: function() { if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this; var __method = this, args = $A(arguments), object = args.shift(); return function() { return __method.apply(object, args.concat($A(arguments))); } } a.bind(b, …);
    18. 18. Source Code Analysis Inheritance and creating class in Prototype Library.
    19. 19. OOP/Inheritance There are 3 ways to implement inheritance. a.prototype chain b.Properties copy c.Using apply/call functions
    20. 20. Source Code Analysis Inheritance in YUI and Mootools
    21. 21. JScript (IE) SpiderMonkey(FF) JavaScriptCore(Safari) linear_b(Opera) DOM/HTML JavaScript Engine
    22. 22. While JavaScript is the programming language which will allow you to operate on the DOM objects and to manipulate them programmatically, the DOM will provide you with methods and properties to retrieve, modify, update, and delete parts of the document you are working on. If a web page were a piece of imported Swedish furniture, the DOM would be the illustrations of the parts - the shelves, bolts, Allen wrenches and screwdrivers. The Document Object Model, a language-neutral set of interfaces Keywords: W3C DOM Level1 and DOM Level2, XML, SAX
    23. 23. HTML DOM STRUCTURE
    24. 24. Html type nodeType name nodeType value Element Node.ELEMENT_NODE 1 Element Node Text Node.TEXT_NODE 3 Text Node Document Node.DOCUMENT_NODE 9 document Comment Node.COMMENT_NODE 8 Comment DocumentFragment Node.DOCUMENT_FRAGMENT_NODE 11 Fragment Attr Node.ATTRIBUTE_NODE 2 Attribute The NodeType and NodeType Value e.g. alert(document.nodeType);
    25. 25. ELEMENT_NODE                                  1 ATTRIBUTE_NODE                             2 TEXT_NODE                                          3 CDATA_SECTION_NODE                  4 ENTITY_REFERENCE_NODE             5 ENTITY_NODE                                      6 PROCESSING_INSTRCTION_NODE        7 COMMENT_NODE                              8 DOCUMENT_NODE                             9 DOCUMENT_TYPE_NODE                10 DOCUMENT_FRAGMENT_NODE    11 NOTATION_NODE                               12 All The NodeType and NodeType Value
    26. 26. createAttribute() createComment() createElement() createTextNode() getElementById() getElementsByTagName() Document Methods getAttribute() getAttributeNode() getElementsByTabName() hasAttribute() removeAttribute() removeAttributeNode() setAttribute() setAttributeNode() Element Methods
    27. 27. attributes childNodes firstChild lastChild nextSibling nodeName nodeType parentNode previousSibling appendChild() cloneNode() hasChildNodes() insertBefore() removeChild() replaceChild() Node Properties & Methods What’s the differences between Node and Element ?
    28. 28. The theory of DOM can be applied to other every dom manipulation, and other languages. e.g. XML, XHTML, WML… e.g. PHP, Java, C#... Ref erence: http://www.w3schools.com
    29. 29. Thank you! http://neticy.com http://www.joke4me.com Robbin.joe@gmail.com Happy Tiger Year!

    ×