I have a function that is bound to a React component:
functionName(param1, param2 = this.state.field) {
}
I've never heard of the 'this' keyword being used within a function signature in Javascript and am wondering if the context of 'this' will be the containing object or the global scope. Does this function need to be bound to the proper context before I can use 'this' properly within the signature?
I am wondering if the context of 'this' will be the containing object or the global scope.
Neither. Default values are not evaluated outside the function, but inside the call. The this
keyword will point to the same value it would in the body of the method - the receiver of the call. So if the function was bound to your react component, that is what this
will be.