hi i want to know how to create objects in both javascript and jquery.
something like this.
Person = new Person();
Person.name = "John Doe";
Person.age = "16";
It is possible? Any help will do. Thank you
update #follow-up
If i’m able to create an object using javascript can i pass the object i recently created to a ajax request in jquery?
jQuery is made using (or is) JavaScript, you can do this to work in both:
You can pass arguments to constructor function as well:
And add methods inside constructor or
prototypetoo (I prefer latter):Or better using
prototype:Now you can create as many instances as you want:
Result:
Good Practices:
Always capitalize the first letter of constructor function (as in
Person) so that people could know that it has to be instantiated withnewkeyword.Generally/mostly it is good idea to add methods via
prototypeproperty (as shown above).