February 2019
Beginner
694 pages
18h 4m
English
By having access to the full class definition, we can use simple string searching to find the properties of the class constructor. If we find the first open bracket '(' character, and the next close bracket ')' character, we can extract a string that contains all of our constructor parameter names. Let's update our ConstructorDecorator code, as follows:
let firstIdx = classDefinition.toString().indexOf('(') + 1;
let lastIdx = classDefinition.toString().indexOf(')');
let arr = classDefinition.toString().substr(
firstIdx, lastIdx - firstIdx);
console.log(`class parameters :`);
console.log(`${arr}`);
console.log(`==================`);
The output of this code is as follows:
================ class parameters :
Read now
Unlock full access