Tips for JavaScript / PDF


Tips for JavaScript / PDF

Tips for JavaScript / PDF






Sample of the PDF document 







Objectives

• Learn how to make JavaScript code execute faster.
• Explore techniques for caching JavaScript code.
• Understand the cost of using objects and methods.





Creating Prototypes
The prototype property lets you define and add custom methods and properties to objects. Before using the prototype property to assign a method, create a function that defines what actions will be performed. Use the JavaScript keyword this inside your function to refer to the current instance of the object.

To have the method return a value to the user, use the JavaScript keyword return.

Once you have created your function, you can assign it as a method. Thesyntax for assigning a function to a prototype is as follows:

.prototype. = name>

NOTE :Never list the arguments of a function when assigning the function as a method. If you don’t, a syntax error will result and the function will never get called.

String Prototypes
Use the string prototype to add properties and methods to the String object. For
example you may add a compare method that takes a string as an argument and
returns true if they are equal or false if they are not. Here is an example of
creating and using a string prototype:



Number Prototypes
Use the number prototype to add properties and methods to the Number object.

For example you may add a method that converts a string into a number. Here is an example of creating and using a number prototype:



Date Prototypes
Use the date prototype to add properties and methods to the Date object. For example you may add a method that determines the number of days between two dates. Here is an example of creating and using a date prototype:......






Download Tips for JavaScript / PDF








Tips for JavaScript / PDF






0 commentaires: