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 |
Is javascript backend or frontend?
What is a name function in javascript & how to define it?
How to get an element by class in javascript ?
What is difference between promise and callback?
What are the different actions that are performed using javascript?
How to create an input box?
What does break and continue statements do in javascript?
Which operator is used to assign a value to a variable?
Write a Program of Simple Calculator in JavaScript using HTML.
what is the purpose of using jsp?
What are the methods of validating whether the form is secure?
What web sites do you feel use javascript most effectively (i.e., Best-in-class examples)? The worst?