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
How do Javascript primitive/object types passed in functions?
Do I need var in javascript?
What is the difference between undefined and object?
Where is javascript used most?
Where should I put script tags?
Explain unescape() and escape() in javascript?
What are the uses of javascript in web page designing?
20 Functions of Selenium with description and Examples.
Explain the for-in loop?
What is Unobtrusive JavaScript & Why it's Important?
What is enum data type?
What are all the types of Pop up boxes available in JavaScript?
What is a boolean search?
Explain the process of document loading.
What are the different boolean operators in JavaScript?