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 much do javascript programmers make?
What is the difference between var and let?
Is javascript the future?
What is difference between local variable and global?
How do I start a javascript project?
What are arrays in javascript?
How will you get the checkbox status whether it is checked or not?
What does “1?+2+4 Evaluate to? What about 5 + 4 + “3??
What is are the types of the pop up box es available in javascript?
What is Unobtrusive JavaScript & Why it's Important?
In which location cookies are stored on the hard disk?
Should you use var or let?
Explain event bubbling and event capturing in javascript?
What would be the result of 2+5+”3″?
What is string in javascript?