我只看到人们传递两个函数的例子,但没有同时传递prop和函数。假设我想同时通过onClick={props.tested}
(道具)和onClick={divTested}
(功能)。我该怎么做??
虽然我很少看到这样做,但您确实可以向函数添加属性,并将属性传递给该函数。到另一个知道这些属性的函数中:
let functionWithProperties = function(a, b)
{
return a + b;
}
// Add Properties to the function:
functionWithProperties.a = 5;
functionWithProperties.b = 10;
function doSomethingWithFunctionWithProperties(func)
{
return func(func.a,func.b);
}
// Pass function with properties into another function
// that is aware of those properties:
let output = doSomethingWithFunctionWithProperties(functionWithProperties);
console.log(output); // 15