问题
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
回答1:
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) {
// ---------------------------------------------------^
来源:https://stackoverflow.com/questions/48488873/lexical-declaration-problems-with-default-params