Saltar al contenido principal
Dibyendu Shankar Tiwary Javascript Unleashed (Javascript that you need to know but might not!!)
What is Javascript ? Introduction
It makes the wall to talk Introduction
What’s behind the scene? Introduction
Equation
I know it all Tell me something which I don’t know
Why are we here? JavaScript as a prototype-based language  JavaScript Objects Are Dictionaries   JavaScript Functions Are First Class   Constructor Functions but No Classes   Prototypes   Object-oriented programming with JavaScript Static Properties and Methods   Closures   Simulating Private Properties  Inheriting from Classes Coding tricks with JavaScript   Simulating Namespaces  Classes and Reflection Future of Javascript   Should You Code JavaScript This Way?  Putting It into Perspective
JavaScript Objects Are Dictionaries   Code Demo JavaScript Functions Are First Class   Code Demo Constructor Functions but No Classes Code Demo (Dog spot = new Dog(); ) Prototypes (I deserve to be a header of a slide) As you wish, but be sure you gonna use it. JavaScript as a prototype-based language
Every Function’s Prototype Has a Constructor Property  The prototype object is a central concept in object-oriented programming with JavaScript. Name comes from the idea that in JavaScript, an object is created as a copy of an existing example (that is, a prototype) object every function has a property named "prototype" that refers to a prototype object prototype object in turn has a property named "constructor," which refers back to the function itself (Confused ??) Code Demo : var buddy = new Dog(“Buddy“);  Prototypes (Happy   )
Objects Appear to Have Their Prototype’s Properties  Code Demo Prototypes (Another slide conquered)
Resolving toString() Method in the Prototype Chain Prototypes (Are you kinda hittin on me ??)
Inheriting from a Prototype Changes made to a prototype object are immediately visible to the objects that inherit from it, even after these objects are created. If you define a property/method X in an object, a property/method of the same name will be hidden in that object’s prototype. For instance, you can override Object.prototype’s toString method by defining a toString method in Dog.prototype. Changes only go in one direction, from prototype to its derived objects, but not vice versa. Code Demo Prototypes (Name the session after me)
Static Properties and Methods   Code Demo Closure   A closure is a runtime phenomenon that comes about when an inner function (or in C#, an inner anonymous method) is bound to the local variables of its outer function.  Confused?? ( Code demo is for the rescue) Simulating Private Properties A local variable in a function is normally not accessible from outside the function However, when that local variable is captured by an inner function’s closure, it lives on. Code Demo javascript.crockford.com Inheriting from Classes (Even I deserve a slide, Ok whatever!!) Oops in Javascript
Constructor functions and prototype objects allow you to simulate classes Can simulate private members of a class using closures  You haven’t seen how you can derive from your class A local variable in a function is normally not accessible from outside the function However, when that local variable is captured by an inner function’s closure, it lives on. Code Demo javascript.crockford.com You have a base class Pet, with one derived class Dog.  Stop talking show me the code. Inheritance from Classes (Happy   )
Simulating Namespaces In C++ and C#, namespaces are used to minimize the probability of name collisions Code Demo Classes and Reflection  there is no way to know the name of a function.  it wouldn’t help us in most situations as a class constructor is typically built by assigning an anonymous function to a namespaced variable. The reflection APIs in ASP.NET AJAX work over any type. Coding tips and Tricks in JavaScript
Should You Code JavaScript This Way? Should you code in JavaScript the way you code in C# or C++? Best practices for one language may not be the best practices for another Maybe, as Douglas Crockford says in his article " Prototypal Inheritance in JavaScript ", the JavaScript way of programming is to make prototype objects, and use the simple object function below to make new objects, which inherit from that original object: function object(o) { function F() {} F.prototype = o; return new F(); } Putting It into Perspective   I have found my JavaScript journey a rewarding experience.  Although not entirely without frustration along the way Registering Class Hierarchies and Calling Base.  It’s a journey not a destination. Future of Javscript
Thank you  ( If you are confused now I have done a good job, if not then an exceptional job   )