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 |
Which built-in method returns the string representation of the number’s value?
What is scope variable in javascript?
Which built-in method returns the calling string value converted to lower case?
What is innertext javascript?
How do I view javascript files in chrome?
How to detect the OS on the client machine in JavaScript?
What are the valid scopes of a variable in JavaScript?
Write JavaScript code to use file system in binary format?
How does javascript work?
What does the following statement declares?
Create a new javascript object with the keys of “fname” equal to your first name, “lname” equal to your last name, and “fcolors” equal to and array of 3 of your favorite colors. Assign this object to a variable called “me” and log it to the console.
What is a prompt box in javascript?