/*
--------------------------
*/
** Pending **
-Methods:
call(), apply(), bind()
**
Book :> The Principle of Object oriented Javscript
**
: Dereferencing Objects //Is used to Clear the memory on browser engine.
var object1 = new Object();
// do something
object1 = null;
// dereference
**
**
: Deleting a value from Object.
> delete objName.key;
**
**
: Function Example -
function reflect(value) {
return value;
}
// is the same as
var reflect = new Function("value", "return value;");
**
**
arrName['push']('3'); //This is also valid ( using bracket notation )
**
** // It will store the values as an Object ( String ).
let nameVariable = new String();
nameVariable.fname = 'Karan';
nameVariable.lname = 'Singh';
**
** hasOwnProperty **
let obj = { fname: "Karan", lname: "Singh" }
> console.log('fname' in obj) //true
> console.log('lname' in obj) //true
> console.log('toString' in obj) //true
// ( Inbuilt methods will also return true )
> console.log(obj.hasOwnProperty('toString')) //False
**
**
//Ways to access Properties in Object
> Object.keys(objName); //Will return keys
> Object.values(objName); //Will return values
**
//To check if Properties are Enumerable (propertyIsEnumerable).
> (objName.propertyIsEnumerable(key)); //true or false
Object.defineProperty(obj, prop, descriptor) //Syntax
**
//We can change the default state of the Object.
var person1 = {};
**
Object.defineProperty(person1, "name", {
value: "Nicholas",
enumerable: true,
configurable: true,
writable: true
}); //It will create 'name' in person1 Object with 'descriptor'.
Object.defineProperty(person1, "name", {
enumerable: false
}); //We can define in Single Lines as well ( Depending upon our need )
Object.defineProperty(person1, 'property1', {
value: 42,
writable: false
});// 'property1' can not be overwritten.
**
//Preventing Object Modification
//Syntax
> Object.preventExtensions(person1); //false
/*It will not allow to add new properties to object 'person1'.
*/
//isExtensible() (How to check?)
> console.log(Object.isExtensible(obj)); //It will tell whether it's extensible or not ( true / false )
**
//Freezing the Object. ( Cant not add/remove. ( read-only ) )
> Object.feeze(objName);
//isFrozen() ( How to Check? )
> console.log(Object.isFrozen(objName)); //Will return true or false.
** //Three methods which does not allow mathods to add/remove properties.
> Object.preventExtensions(objName)
> Object.seal(objName)
> Object.freeze(objName)
//To how to check, Use these methods.
console.log(Object.isExtensible(person1));
console.log(Object.isSealed(person1));
console.log(Object.isFrozen(person1));
**//Using Prototypes with Constructors
function Person(name){
this.name = name;
}
Person.prototype.sayName = function(){
return this.name;
}
let karan = new Person("Jaskaran");
/*
---------------------------------------------------------------------
*/