JavaScript with it's numerous libraries, helps in developing web apps with ease and offers all that an Object Oriented Programming language can offer.
Object oriented Programming is an programming model in which a collection of Objects interact with each other to help you to get your task done.
Being lead by Objects, it is crucial for one to figure out what an Object is and how is can be used, to master this model of programming.
If you are clear with handling Objects, you can just play around with JavaScript. So lets focus on Objects: The hero of our story.
Objects: The Hero
"Everything in JavaScript is an Object". An Object can be a number, a string, an array, a function (method), any primitive type except null or undefined; and what not ... so Almost everything in JavaScript is an Object.
Before getting deep into the world of Objects, There are 2 other terms that you have to be familiar with:
Properties & Methods
Properties: Properties are values that the object possess or Properties are values associated with objects. (Can be compared with Adjectives in English Grammar)
Methods: Methods are actions that objects can perform. (Can be compared with Verbs).
Properties and Methods are object members.
Because JavaScript doesn't have classes and it treats everything as an object, all of a JavaScript Object's members are objects themselves.
So, for our discussion here, any property of an object that is a function, will be considered as a method of the object and every other object member will be considered the object's property.
Example:
Lets consider the most famous Car example to identify the properties and Methods of a Car (Object)
Properties of a car: Name, Model, Weight, Color, ...
car.name = Car Name car.model = Model Name car.weight = Weight in Kg car.color = color of the car
Methods of the car: start, drive, brake
car.start() car.drive() car.brake()
So, as you can see the things that describe a car are it's properties and the things that a car can do are it's methods.
And like our car, an Object in JavaScript can have any number of properties and methods.
Remember, everything is an object in JavaScript - so technically both properties and methods of an object are objects themselves.
We can create our own objects and can assign properties to it.
Creation of Objects:
You can build new JavaScript object in two ways:
Using the new keyword.
Literal declaration.
1) Using The new Keyword:
var ravi = new Object();
Now ravi is your first object defined. The typeof ravi would be object
Accessing Properties of the name(string) property(also an object itself):
console.log(ravi1.name.length); // 9
Accessing Methods of an object:
console.log(ravi1.name.toUpperCase()); // FULL NAME
This is how the objects are defined and object members (Properties and methods) can be accessed.
Although JavaScript doesn't have classes, we can still get class-like functionality with objects - let us look at those in detail, the next time we meet.
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
✓ Live Streaming✓ Interactive Chat✓ Private Shows✓ HD Quality
Anya is LIVE right now
FREE
Free to watch • No registration required • HD streaming
Top Posts Tagged with #javascript beginner | Tumlook