0

The target is to print all properties of a function-object.

Could it be implemented via overwriting the toString-method of the prototype-property (which itself is a function) in the Function-object (is that even the right spot?)?

I know that e.g. following is possible, to modify the single properties with the utility Object.defineProperty which can be used to change properties attributes like e.g. enumerable. After that it would occur in a loop.

Object.defineProperty(Function, 'length', {
  enumerable: true
});

Object.getOwnPropertyDescriptor(Function, 'length')
{value: 1, writable: true, enumerable: true, configurable: true}

for (let a in Function){
    console.log(a);
}

I would like to see the scopes respectively closures that exist in the [[Scopes]]-property, but somehow I think exactly this is not meant to be possible.

3
  • 2
    1/2 ... "The target is to print all properties of a function-object ..." ... Object.entries(Object.getOwnPropertyDescriptors(Function.prototype)).forEach(([key, value]) => console.log([key, JSON.stringify(value)].join(': '))); ... "Is there a possibility to modify the prototype-property" ... the OP just did demonstrate how one would achieve that (then with Function.prototype instead of just Function) ... Commented Dec 30, 2020 at 16:58
  • 2/2 ... "I would like to see the scopes respectively closures that exist" ... one can not retrieve/access such information from the outside. One also can not access scope; one might, within a controlled environment, be able of accessing some data which does exist within scope (regardless of whether being preserved scope) ... There were three questions with the latter one not being related to the chosen topic. What is the OP's real goal? Commented Dec 30, 2020 at 16:58
  • OP's real goal rephrased: By printing out the properties of the function Function, which is a constructor function according to convention written with capital the F, viewing the [[Scopes]]-property and better understanding the handling of scopes by making it tangible how the variables are being managed that are closed over by a closure. Commented Jan 4, 2021 at 7:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.