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
What is javascript in simple terms?
How do I get javascript?
What does trim stand for?
How do I activate javascript on my phone?
What is the use of spread operator?
Will javascript be replaced?
What is a closure and how do you use it?
why we need java instead of c
What are the difference between undefined and not defined in javascript?
Can I declare a variable as CONSTANT in JavaScript?
How to find radio button selection when a form is submitted?
What is the use of history object?
How do you target a specific frame from a hyperlink in javascript?
Which built-in method returns the calling string value converted to lower case?
How to remove duplicate values from a javascript array?