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
TypeError: document.getelementbyid(...) is null?
Some XYZ company is arranging for online aptitude tests. Draw detailed E-R diagram for the same..
What is the use of document object?
What is difference between promise and callback?
How to count the number of element in an array using javascript?
Can you assign an anonymous function to a variable and pass it as an argument to another function?
What is strict mode in javascript?
What are types of javascript?
What do mean by NULL in Javascript?
What is the difference between remove() and removeChild()?
Is javascript frontend or backend?
What is an onclick?
What does parse Query String return in javascript?
can wwe trace a java program (class)
What is undefined x 1 in JavaScript?