How do you create a new object in JavaScript?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

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

1839


What is an object in javascript, give an example?

520


What is this? Var myarray = [[[]]];

588


Does html5 replace javascript?

532


When would you use javascript closures?

475






What is escape() function?

528


How does javascript work?

493


Name the different types of pop up boxes in Javascript?

529


How to get the primitive value of a string in Javascript?

534


What javascript means?

486


What is scope javascript?

555


What are the ways to define a variable in javascript?

500


What are the new ways to define a variable in Javascript?

578


How are DOM utilized in JavaScript?

676


What is console.log() and why it is used?

593