attempting to create a static
function within a react component. the function uses this
to get its data, but this
is out of scope when the function is called.
here is a very simple example:
var Test = React.createClass({ val: 5, statics: { getVal: function() { return this.val } }, render: return( <div>{this.val}</div> ) }); Test.getVal(); => undefined!!
obviously this
has lost its scope when Test.getVal()
is called. how to get this
inside the getVal()
function?
fyi, the following standard javascript parent approach does not work:
Test.getVal.apply( Test ); => undefined
static
is that it's call outside the component in "regular" javascript, which is what I want to do – cc young