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 do I link an external javascript file to html?
Why javascript is dangerous?
Is not a function error in javascript?
What are the uses of javascript in web page designing?
What is prototype in javascript and how do you use it?
What is class example?
How to count the number of element in an array using javascript?
Can you assign a anonymous function to a variable?
What is the difference between java & javascript?
why we need java instead of c
What will be the output of the following statements?
Explain what is pop()method in JavaScript?
What will happen if an infinite while loop is run in Javascript?
How to getting values from cookies to set widgets?
What does js stand for?