here i'm trying explore more object properties using object.getownpropertydescriptor. when used not-static method i'm getting nothing in response. don't know reason behind this.
when use getname method non-static output - undefined
class abc { getname() { return 'abc class name' } } console.log(object.getownpropertydescriptor(abc, 'getname')) when use getname method static output - object {writable: true, enumerable: false, configurable: true}
class abc { static getname() { return 'abc class name' } } console.log(object.getownpropertydescriptor(abc, 'getname'))
this because in first scenario, getname() instance of method of objects of type abc:
let = new abc(); a.getname() //'abc class name' in second scenario, using static keyword creating class method:
abc.getname() //'abc class name' only in second scenario getname set ownproperty abc. in first scenario, getname available on prototype.
Comments
Post a Comment