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

Is html and javascript the same?

0 Answers  


Which built-in method returns the length of the string?

0 Answers  


What is javascript and how it works?

0 Answers  


How do you implement Ajax using hide() function in JQuery?

0 Answers   QuinStreet,


Which built-in method returns the characters in a string beginning at the specified location?

0 Answers  


Define escape() function?

0 Answers  


What is the main difference between Client side JavaScript and and Server side Java Script?

7 Answers   Ramco,


Why javascript is called lightweight language?

0 Answers  


Example of using regular expressions for syntax checking in javascript?

0 Answers  


Where do you write javascript?

0 Answers  


Write a Program using Servlet and JDBC for developing online application for displaying the details of Cars owned by the residents in XYZ society. Make necessary assumptions and create appropriate databases

0 Answers   Ignou,


Event handler Example

1 Answers  


Categories