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 can javascript be used to personalize or tailor a web site to fit individual users?
How to use one javascript function for multiple input fields?
Write a way by which you can do something on the close of the window ?
How to comment javascript code?
Is there any difference between javascript and jscript?
What is the difference between null & undefined?
Can I open javascript on iphone?
Is javascript a dynamic language?
What is the use of math object in javascript?
Do I need to install javascript?
How do I unblock javascript in chrome?
What is client side in javascript?
How many types of data types are there?
How to setting a cookie with the contents of a textbox?
What does the term sticky session mean in a web-farm scenario? Why would you use a sticky session? What is the potential disadvantage of using a sticky session?