I'm adding a custom add() method to the Master Object.prototype so that all the generic objects will be able to access this add() method
Object.prototype.add = function(value1, value2) {
return value1 + value2;
};
Question 1 : How to check if this add() method is enumerable ?
I'm creating a generic object
var obj = {
}
I'm using for-in loop to print all the properties (this should print both own properties and prototype properties)
for (prop in obj){
console.log("property is :" + prop);
}
This printed //property is :add
Question 2: Does for-in loop print both enumerable and non-enumerable properties?
Lets use Object.keys which returns an array of properties (only if enumerable)
var propKeys = Object.keys(obj);
console.log(propKeys); //prints an empty array []
Question 3 : why Object.keys not printing the add property?