Java Script Workshop

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    3 Favorites

    Java Script Workshop - Presentation Transcript

    1. JavaScript WebDU 2009 · Dmitry Baranovskiy
    2. E very object (including host objects) must implement the e)) and ((Class)) propertie s and the ((Get)), ((Put)), ((Prototyp t)), ((HasProperty)), ((Dele te)), and ((DefaultValue)) ((CanPu . (Note, however, that the ((D efaultValue)) method may, methods exception.) The value for some objects , simply throw a TypeError Prototype)) property must be either an object or null, and of the (( Prototype)) chain must have finite length (that is, starting every (( y object, recursively access ing the ((Prototype)) property from an entually lead to a null val ue). Whether or not a native must ev an have a host object as its ((Prototype)) depends on the object c implementation. The value of the ((Class)) property is defined by this specification for every kind of built-i n object. The value of the ((Class)) prop erty of a host object may be any value , even a value used by
    3. E very object (including host objects) must implement the e)) and ((Class)) propertie s and the ((Get)), ((Put)), ((Prototyp t)), ((HasProperty)), ((Dele te)), and ((DefaultValue)) ((CanPu . (Note, however, that the ((D efaultValue)) method may, methods exception.) The value for some objects , simply throw a TypeError Prototype)) property must be either an object or null, and of the (( Prototype)) chain must have finite length (that is, starting every (( from an must ev It is a bit “cryptic” y object, recursively access entually lead to a null val ing the ((Prototype)) property ue). Whether or not a native an have a host object as its ((Prototype)) depends on the object c implementation. The value of the ((Class)) property is defined by this specification for every kind of built-i n object. The value of the ((Class)) prop erty of a host object may be any value , even a value used by
    4. “ECMAScript does not contain proper classes such as those in C++, Smalltalk, or Java, but rather, supports constructors which create objects by executing code that allocates storage for the objects and initialises all or part of them by assigning initial values to their properties.” ECMAScript Specification
    5. Basic Types
    6. Undefined Null Boolean Number String Object
    7. typeof
    8. typeof Undefined \"undefined\" Null \"object\" Number \"number\" Boolean \"boolean\" String \"string\" Object \"object\"
    9. to Number Undefined NaN Null 0 Number — Boolean false ! 0, true ! 1 String parsing Object .valueOf()
    10. to Boolean Undefined !\"#$% Null !\"#$% Number &'())(*+*,(-(.+/01(2(3451 Boolean 6 String 77(-(.+/01(2(3451 Object 89:%
    11. to String Undefined \"undefined\" Null \"null\" Number \"5\" Boolean \"false\" || \"true\" String — Object .toString()
    12. to Object Undefined exception! Null exception! Number new Number(v) Boolean new Boolean(v) String new String(v) Object Object
    13. On the fly
    14. 5 + 4 + \"px\" \"$\" + 1 + 2 \"4\" / \"2\" \"$\" + 1 - 2 \"webdu\".length typeof 5 typeof \"5\" typeof {property: value} typeof null typeof undefined typeof [1, 2, 3] typeof (4 - \"px\")
    15. 5 + 4 + \"px\" \"9px\" \"$\" + 1 + 2 \"$12\" \"4\" / \"2\" 2 \"$\" + 1 - 2 NaN \"webdu\".length 5 typeof 5 \"number\" typeof \"5\" \"string\" typeof {property: value} \"object\" typeof null \"object\" typeof undefined \"undefined\" typeof [1, 2, 3] \"object\" typeof (4 - \"px\") \"number\"
    16. Object Properties
    17. ReadOnly DontEnum DontDelete Internal
    18. for in
    19. var a = { x: 12, y: 23, r: 10, draw: function () {/*...*/} }; for (var property in a) { alert(\"a.\" + property + \" = \" + a[property]); }
    20. var a = { x: 12, y: 23, r: 10, draw: function () {/*...*/} }; for (var property in a) { alert(\"a.\" + property + \" = \" + a[property]); }
    21. Function Array Date RegExp
    22. Function
    23. var y = 1; function x() { var y = 2; return ++y; } var z = function () { return ++y; };
    24. function x() { var y = 2; return function () { return ++y; }; } var a = x(); a(); a();
    25. arguments
    26. function add(a, b) { return a + b; } add(4, 5); // = 9 add(4, 5, 6, 7, 8, 9) // = 39 function add() { var sum = 0; for (var i = 0, ii = arguments.length; i < ii; i++) { sum +=+ arguments[i]; } return sum; }
    27. Scope & “this”
    28. function is(it) { alert(this + \" is \" + it); } is(\"global\"); is.call(5, \"number\"); is.apply(\"A\", [\"string\"]); alert.is = is; alert.is(\"function\");
    29. Variable declaration
    30. alert(b); 1 b = 1; alert(a); 2 var a = 1; (function () { 3 var x = 1; })(); alert(x); (function () { 4 y = 1; })(); alert(y);
    31. Function declaration
    32. function x(a) { 1 return a && x(--a); } var x = function (a) { 2 return a && x(--a); }; setTimeout(function (a) { 3 return a && arguments.callee(--a); }, 1000); var x = function y(a) { 4 return a && y(--a); }; setTimeout(function y(a) { 5 return a && y(--a); }, 1000);
    33. Arrays declaration
    34. var a = new Array(); var a = new Array(3); var a = []; var a = [undefined, undefined, undefined]; var a = [1, 2, 3, 4];
    35. Object declaration (JSON)
    36. var a = new Object(); var a = {}; var a = {x: 10, y: 15}; var a = { x: 10, name: \"object\", \"font-style\": \"italic\", getHeight: function () {/*...*/}, points: [1, 2, 3], child: {x: 10, y: 15} };
    37. OOP
    38. “Object Owns Prototype”
    39. var mouse = { 1 name: \"Mike\", voice: function () { alert(\"Squik!\"); } }; var o = new Object(); 2 o.name = \"Mike\"; o.voice = function () { alert(\"Squik!\"); }; var O = function () { 3 this.name = \"Mike\"; this.voice = function () { alert(\"Squik!\"); }; }; var o = new O(); var O = function () {}; 4 O.prototype.name = \"Mike\"; O.prototype.voice = function () { alert(\"Squik!\"); }; var o = new O();
    40. Inheritance
    41. Inheritance
    42. Delegation
    43. Classic Model Class Object Class Object Object Object
    44. Prototypal Model Object Object Object Object
    45. Object Object
    46. // Sharing function Parent(value) { this.value = value; } Parent.prototype.getValue = function () { return this.value; }; function A(value) { this.value = value + 1; } A.prototype = new Parent(); function B(value) { this.value = value * 2; } B.prototype = new Parent(); alert((new A(5)).getValue()); // 6 alert((new B(5)).getValue()); // 10
    47. // Sharing function A(value) { this.value = value + 1; } function B(value) { this.value = value * 2; } A.prototype.getValue = B.prototype.getValue = function () { return this.value; }; alert((new A(5)).getValue()); // 6 alert((new B(5)).getValue()); // 10
    48. Array
    49. Date
    50. RegExp
    51. Thank You

    + Dmitry BaranovskiyDmitry Baranovskiy, 6 months ago

    custom

    659 views, 3 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 659
      • 659 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 3
    • Downloads 23
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories