Fichas
Sin título
Fichas del conjunto (2)
- 1Object constructorThere are many ways to create objects in javascript as below
Object constructor:
The simplest way to create an empty object is using the Object constructor. Currently this approach is not recommended.
var object = new Object();
Object's create method:
The create method of Object creates a new object by passing the prototype object as a parameter
var object = Object.create(null);
Object literal syntax:
The object literal syntax is equivalent to create method when it passes null as parameter
var object = {};
Function constructor:
Create any function and apply the new operator to create object instances,
function Person(name){
var object = {};
object.name=name;
object.age=21;
return object;
}
var object = new Person("Sudheer");
Function constructor with prototype:
This is similar to function constructor but it uses prototype for their properties and methods,
function Person(){}
Person.prototype.name = "Sudheer";
var object = new Person();
This is equivalent to an instance created with an object create method with a function prototype and then call that function wi - 2—
Información
- Descripción
- Fichas sobre Sin título, creado por Sam Saiden el 27/01/2021.
- Creado por
- Sam Saiden
- Visitas
- 1
- Valoración