How do you create a new object in JavaScript?

Answers were Sorted based on User's Feedback



How do you create a new object in JavaScript?..

Answer / sri

The following function can be used as demonstrated to create
an object of class myobject:

function myobject() {
this.containedValue = 0;
this.othercontainedValue = 0;
this.anothercontainedValue = 0;
}

var mything = new myobject();
And there you go, mything is now an instance of class
myobject. It will have the following properties, all of
which will be 0:

* mything.containedValue
* mything.othercontainedValue
* mything.anothercontainedValue

You could also now write
myobject.prototype.newContainedValue = someValue; and all
instances of class myobject will have the property
newContainedValue with value someValue.

Is This Answer Correct ?    7 Yes 4 No

How do you create a new object in JavaScript?..

Answer / nidz

var myObject={} this also creates a new object

Is This Answer Correct ?    4 Yes 2 No

How do you create a new object in JavaScript?..

Answer / elan

var newObject;

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More JavaScript Interview Questions

In javascript what is an argument object?

0 Answers  


Is it possible to do 301 redirects in javascript ?

0 Answers  


How to make a array as a stack using javascript?

0 Answers  


What applications use javascript?

0 Answers  


What is the difference between the keywords var and let?

0 Answers  






what is eval pls breif information send me

1 Answers  


How we can add title of the page by javascript?

0 Answers  


What is an object in javascript, give an example?

0 Answers  


Difference between window.onload and onDocumentReady?

0 Answers  


What is a class in javascript?

0 Answers  


What is JavaScript?

0 Answers  


What is an onclick?

0 Answers  


Categories