background preloader

Javascript

Facebook Twitter

SVG

JavaScript Java Script Programming. JavaScript Guide - JavaScript. JavaScript and Object Oriented Programming (OOP) JavaScript and Object Oriented Programming (OOP) Credits: This tutorial is written and contributed by Tim Scarfe. Edited by JavaScriptKit.com for content/ structure. Please see footnote for more information on author.

JavaScript is an excellent language to write object oriented web applications. What's so great about objects? Objects work so well because they act just like real life objects- objects have properties and methods. JavaScript gives you the ability to make your own objects for your own applications. Creating objects using new Object() There are several ways to create objects in JavaScript, and all of them have their place. We define a custom object "person," then add to it its own properties and method afterwards. Creating objects using Literal Notation Another inline way of defining an object is via literal notation. Associative arrays, looping, and JScript.NET. Objects as Associative Arrays As you may know, the dot (.) operator can be used to access the [] operator used with arrays. The important thing to notice is that in the object syntax the property is an identifier, whereas in the array syntax, it's a string.

The obvious benefits of using an array syntax to access an object is because of the literal data type, you can easily concat strings and play around with them to access an object. For this to work with the standard syntax, an eval() would need to be used. How do I loop through properties in an object? You need to use a for/in loop. What about JScript.NET? Once you have mastered JScript, you will find it easy to move over to .NET As the .NET compiler will compile your code into the IL (Intermediate Language) you have the same power to create fully fledged applications as a C# programmer. If you are making complicated Interfaces and such, there is no automatic recognition for this.

You may now explicitly set the data type for a variable.