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 is node ecosystem?

0 Answers  


HI friends .am Mohammed Riyash.JMC BCA Tricy. My doubt is. In some websites like bloomberg.com..etc. when MouseOver() action performed.the menuitems will be drop down..and hides when blur()action happened.any body give the code for that..

1 Answers   iGate, Reliance,


What is the use of a date object in javascript?

0 Answers  


Which parameter of load ()' s callback function has the data?

1 Answers  


what is function of stdio.h

0 Answers   TCS,


Example of using regular expressions for syntax checking in javascript?

0 Answers  


What is new function in javascript?

0 Answers  


What is negative infinity?

2 Answers   CoKinetic, Satyam,


What's relationship between JavaScript and ECMAScript? And What are JavaScript types?

0 Answers   MCN Solutions,


How to access an external javascript file that is stored externally and not embedded?

0 Answers  


Does apple use javascript?

0 Answers  


What is createtextnode?

0 Answers  


Categories