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

What does the enableviewstatemac setting in an aspx page do?

0 Answers  


What causes memory leaks?

0 Answers  


What is a function callback?

0 Answers  


How do I activate javascript on my phone?

0 Answers  


What are the advantages of javascript?

0 Answers  






how can we retrieve value from one database server and store them another database server using sql server code

0 Answers   HP,


Is there any class in javascript?

0 Answers  


What are the problems associated with using javascript, and are there javascript techniques that you discourage?

0 Answers  


How to import all exports of a file as an object.

0 Answers  


Are there any training Institutions on iphone Automation testing?

0 Answers  


What are events in javascript?

0 Answers  


Why is javascript so hard?

0 Answers  


Categories