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
Is javascript necessary?
What is difference between array.splice() and array.slice() method in javascript?
What is the difference between call & apply?
How do you implement Ajax using hide() function in JQuery?
How to read elements of an array in JavaScript?
What percentage of websites use javascript?
What is let keyword in typescript?
What is the use of a weakmap object in javascript?
What are the ways to define a variable in javascript?
What is the === in javascript?
20 Functions of Selenium with description and Examples.
Can you give an example showing javascript hoisting?
What is an asynchronous programming? Why is it important in javascript?
What is camelcase in programming?
What do you mean by enumeration?