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 |
Taking a developer's perspective, do you think that that javascript is easy to learn and use?
Does html5 replace javascript?
What is a closure javascript? Explain
Should I learn java first or javascript?
What is the use of blur function?
What are the pop-up boxes available in javascript?
What are the data types in js?
What are the properties of stack?
What is the difference between the keywords var and let?
How will you get the checkbox status whether it is checked or not?
What is the difference between undefined and not defined in JavaScript?
Why javascript is called lightweight language?