JavaScript constructors -


i not understand quite how apply constructors on object creation method:

 var myobject = {    ... }; 

i know can do:

 var myobject = new object(); myobject.prototype.constructor = function(props) {   ... } 

or...

 function myobject(prop1, prop2) {  this.prop1 = prop1;  ... } 

can this?

 var myobject = {    myobject: function(prop1, prop2)    {      ...    } } 

no, can't, create (static) method on myobject -- myobject.myobject. in javascript, constructor is class. class methods , properties created either inside constructor using this. or adding prototype (outside of constructor) using myclass.prototype.. can think of "objects" in javascript static classes.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -