Home > Javascript > Object Oriented JavaScript

Object Oriented JavaScript


Creating a class

Use object oriented javascript.
Below code write in .js file.
First of all declare a class. In JavaScript  class declaration same as function.
Let create a class in JavaScript
function MyClass(){
}
Now create a function in this class
function MyClass(){
this.firstFunction = firstFunction;
function firstFunction(){
alert(“I am from class”);
}
Now call the class function through object.  So we need to create object that
class.
var obj = new MyClass();
obj.firstFunction();

OutPut: A alert msg “I am from class”.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: