Skip to content

Commit

Permalink
updates on naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
wentout committed Aug 4, 2022
1 parent 188eb8d commit 9b9fa96
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
11 changes: 6 additions & 5 deletions build/api/types/compileNewModificatorFunctionBody.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value : true });
const compileNewModificatorFunctionBody = function (FunctionName, asClass = false) {
const dt = `${Date.now()}_${`${Math.random()}`.split('.')[1]}`;
const modString = asClass ?
`class ${FunctionName} extends ConstructHandler {
`class ${FunctionName} extends ConstructHandler_${dt} {
constructor(...args) {
const answer = super(...args);
return CreationHandler.call(this, answer);
return CreationHandler_${dt}.call(this, answer);
}
}`
:
`const ${FunctionName} = function (...args) {
const answer = ConstructHandler.call(this, ...args);
return CreationHandler.call(this, answer);
const answer = ConstructHandler_${dt}.call(this, ...args);
return CreationHandler_${dt}.call(this, answer);
};`;
return new Function('ConstructHandler', 'CreationHandler', 'SymbolConstructorName', `return function () {
return new Function(`ConstructHandler_${dt}`, `CreationHandler_${dt}`, 'SymbolConstructorName', `return function () {
${modString}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mnemonica",
"version": "0.9.942",
"version": "0.9.943",
"description": "abstract technique that aids information retention : instance inheritance system",
"type": "commonjs",
"main": "./build/index.js",
Expand Down
22 changes: 14 additions & 8 deletions src/api/types/compileNewModificatorFunctionBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
/*
// it is not that easy
// constructor name diappears
// frome the debugger and so on...
// constructor name diappears when you look on 'this'
// using Chrome Dev tools debugger for example
// adding 'debugger;' keyword next line to
// 'const answer = ' see example down below
// thought for console.log it is there
// Also, as it is written here
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
// the name of the function might be obfuscated during bundling
// therefore it seems to be more correct to implement new Function
// therefore it seems to be more correct to implement using 'new Function'
// however, for better understanding of what is going on here
// I'd like to provide solution with preliminary compiled functions
Expand All @@ -21,6 +23,7 @@ const getClassConstructor = ( ConstructHandler: any, CreationHandler: any, ) =>
return class extends ConstructHandler {
constructor ( ...args: any[] ) {
const answer = super( ...args );
debugger;
return CreationHandler.call( this, answer );
}
};
Expand All @@ -29,6 +32,7 @@ const getClassConstructor = ( ConstructHandler: any, CreationHandler: any, ) =>
const getFunctionConstructor = ( ConstructHandler: any, CreationHandler: any, ) => {
return function ( this: any, ...args: any[] ) {
const answer = ConstructHandler.call( this, ...args );
debugger;
return CreationHandler.call( this, answer );
};
};
Expand Down Expand Up @@ -60,24 +64,26 @@ const compileNewModificatorFunctionBody = function ( FunctionName: string, asCla
*/

const compileNewModificatorFunctionBody = function ( FunctionName: string, asClass: boolean = false ) {

const dt = `${Date.now()}_${`${Math.random()}`.split('.')[1]}`;

const modString = asClass ?

`class ${FunctionName} extends ConstructHandler {
`class ${FunctionName} extends ConstructHandler_${dt} {
constructor(...args) {
const answer = super(...args);
return CreationHandler.call(this, answer);
return CreationHandler_${dt}.call(this, answer);
}
}`

:

`const ${FunctionName} = function (...args) {
const answer = ConstructHandler.call(this, ...args);
return CreationHandler.call(this, answer);
const answer = ConstructHandler_${dt}.call(this, ...args);
return CreationHandler_${dt}.call(this, answer);
};`;

return new Function( 'ConstructHandler', 'CreationHandler', 'SymbolConstructorName',
return new Function( `ConstructHandler_${dt}`, `CreationHandler_${dt}`, 'SymbolConstructorName',
`return function () {
${modString}
Expand Down

0 comments on commit 9b9fa96

Please sign in to comment.