0

I'm having some problems when defining some functions after declaring a class.

I've used default params before when declaring functions, but I don't know if I can use a function or class as default parameter too.

My code is this

const Matrix = class {/*...some code...*/}

const sigmoid = function(A, flag = false, factor = 1, Matrix = Matrix) {
    /*my functions declaration*/
}

Here I have the problem.

var result1 = sigmoid( Matrix.dot( [[val1, val2]], res.W1 ) , false, 1)
var result2 = sigmoid( Matrix.dot(result1, res.W2), false, 1)

In the line of const sigmoid = ... it said can't access lexical declaration `Matrix' before initialization

Fernando Carvajal
  • 1,869
  • 20
  • 19

1 Answers1

2

You're shadowing your Matrix identifier in the declaration by doing this:

const sigmoid = function(A, flag = false, factor = 1, Matrix = Matrix) {
// ---------------------------------------------------^

That means the Matrix after the = is the parameter, not the class identifier.

Just use a standard lower-case parameter name instead:

const sigmoid = function(A, flag = false, factor = 1, matrix = Matrix) {
// ---------------------------------------------------^
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875