+ 78

WHAT Is The Java-Script Object Constructors ?!?

Object Constructors in Java-Script

9th Dec 2018, 8:34 PM
M.h_B
M.h_B - avatar
9 Respostas
+ 23
Hello, 😊 Finish the JavaScript tutorial and you will learn basics of ES6! ;) --> Class contains a 'constructor' method for initializing. https://www.sololearn.com/learn/JavaScript/2979/ https://code.sololearn.com/W0z5Q7x62DtS/?ref=app https://code.sololearn.com/W5V90UbGotU9/?ref=app
9th Dec 2018, 9:27 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 16
Gordon You're right,👍 I did not understand the question, because I did not create an object on this way! I put in here an incomplete javascript code "How to create an object in JavaScript" , and now I see where is the answer, thanks to you! đŸ˜„đŸ» function Person(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; } Person.prototype.sayHi = function() { return this.firstName +" "+ this.lastName +" says hello!"; } Person.isPerson = function(person) { return person.constructor === Person; }
10th Dec 2018, 9:40 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 7
If you like to learn from step-by-step video, this is a good one. Javascript class tutorial by Biel Blue https://www.sololearn.com/post/38381/?ref=app
10th Dec 2018, 2:39 AM
Gordon
Gordon - avatar
+ 6
They are like prototypes that can be used to create many other objects
10th Dec 2018, 8:50 AM
Ismail
Ismail - avatar
+ 5
M.h_B after careful reexamination your question and Danijel's code and comment to his code, I suggest you look into the JS scripts and comment of Danijel's code [ES6:] Class Syntax. Looks like the Object constructor you asking is the pre-ES6 way to define class constructor.
10th Dec 2018, 9:29 AM
Gordon
Gordon - avatar
+ 5
Having a good understanding of constructors is crucial to truly understand the JavaScript language. Unlike many other languages, JavaScript doesn't support classes, but it has constructors to bring similar functionality to JavaScript. In this tutorial, we will explore constructors in detail and see how JavaScript utilizes them to make objects. Constructors are like regular functions, but we use them with the "new" keyword. There are two types of constructors: native (aka built-in) constructors like Array and Object, which are available automatically in the execution environment at runtime; and custom constructors, which define properties and methods for your own type of object. function Book() { // unfinished code } var myBook = new Book(); The last line of the code creates an instance of Book and assigns it to a variable; even though the Book constructor doesn't do anything, myBook is still an instance of it. As you can see there is no difference between this function and regular functions except that we call it with the new keyword and the function name is capitalized. https://crbtech.in/java-training/best-advanced-java-training-institutes-pune-top-certification
10th Dec 2018, 12:25 PM
meenal deshpande
+ 4
an object constructor is basically a function that takes parameters. once the function is called, it sort of becomes an object literal in which the parameters you plugged in become the properties of the object
18th Dec 2018, 12:52 PM
Nikki Luzader
Nikki Luzader - avatar
11th Jan 2019, 12:41 AM
Gordon
Gordon - avatar
- 1
Mikhay bdoni chie???????? Poshte sareto negah kon
24th Feb 2019, 8:10 AM
Vahid
Vahid - avatar