How do you create a new object in JavaScript?
Answers were Sorted based on User's Feedback
Answer / 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 |
How to create an object using javascript?
How to redirect a url using JavaScript?
What companies use javascript?
How can an HTMLCollection be traversed?
What is the use of type of operator?
How do you disable javascript?
What is difference between var x =1; and x=1;?
Do you have to declare variables in javascript?
What is viewstate in javascript?
What are the difference between javascript and jquery?
what is onfocus and onblur events in java script?
What is closure?