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
Are there any training Institutions on iphone Automation testing?
What is strict mode in javascript?
What does 3 dots mean in javascript?
How do I disable javascript in my browser?
Can you explain the difference between == and ===?
Difference between window.onload and onDocumentReady?
Does javascript have the concept level scope?
What is the difference between window and document in Javascript?
How do you add an element at the beginning of an array?
What is the difference between rootscope and scope?
What is the importance of