function

TypeError:Cannot read property 'map' of undefined in reactjs

末鹿安然 提交于 2021-02-19 06:16:27
问题 I'm using React.js. I want to use the data I have captured in Mock Api in product detail in an e-commerce site, but I get the following error. My goal here is to extract and print data from Mock API in ProductDetail. ProducDetail.js; const ProductDetail = (props) => { const { name, description, price } = props; const axios = require('axios'); const [dress, setDress] = useState([]); useEffect(() => { axios .get(`{url}`) .then(function (response) { setDress(response.data.dress); }) .catch

A container of std::function with polymorphic types as function arguments

我与影子孤独终老i 提交于 2021-02-19 05:22:17
问题 I would like to have "yet another" callback registration stuff. Different event types extending a common base event type will trigger associated callback functions. here is the initial draft or idea #include <functional> #include <iostream> #include <unordered_map> class BaseEvent { public: virtual ~BaseEvent() {} }; class DerivedEvent_1 : public BaseEvent {}; class DerivedEvent_2 : public BaseEvent {}; // a container holding callback functions std::unordered_map<size_t/*event*/, std:

Call php function from bash - with arguments

余生颓废 提交于 2021-02-19 05:20:25
问题 I have a simple func.php file with concat function: <?php function concat($arg1, $arg2) { return $arg1.$arg2; } ?> I would like to call this function from linux bash shell with two arguments : 1st: "Hello, " 2nd: "World!" and print the output ("Hello, World!") to linux bash shell. Please tell me, how to do it? 回答1: What you want is $argv So for example, your script would be called like this: php /path/to/script.php 'Hello, ' 'World!' Then in your PHP file: <?php $arg1 = $argv[1]; $arg2 =

Why use staticmethod instead of no decorator at all

徘徊边缘 提交于 2021-02-19 04:34:04
问题 There are several good explanations on SO about why/when you should use a class method vs a static method, but I've not been able to find an answer for when you would use a static method over no decoration at all. Consider this class Foo(object): @staticmethod def f_static(x): print("static version of f, x={0}".format(x)) def f_standalone(x): print("standalone verion of f, x={0}".format(x)) And some output: >>> F = Foo >>> f = F() >>> F.f_static(5) static version of f, x=5 >>> F.f_standalone

Casting from member pointer to whole struct/class

a 夏天 提交于 2021-02-19 03:50:26
问题 Consider following code: #include <iostream> struct bar { double a = 1.0; int b = 2; float c = 3.0; }; void callbackFunction(int* i) { auto myStruct = reinterpret_cast<bar*>(i) - offsetof(bar, b); std::cout << myStruct->a << std::endl; std::cout << myStruct->b << std::endl; std::cout << myStruct->c << std::endl; //do stuff } int main() { bar foo; callbackFunction(&foo.b); return 0; } I have to define a callback function and I want to use some additional information in that function. I defined

What are the implications of having an “implicit declaration of function” warning in C?

喜夏-厌秋 提交于 2021-02-19 03:49:50
问题 As the question states, what exactly are the implications of having the 'implicit declaration of function' warning? We just cranked up the warning flags on gcc and found quite a few instances of these warnings and I'm curious what type of problems this may have caused prior to fixing them? Also, why is this a warning and not an error. How is gcc even able to successfully link this executable? As you can see in the example below, the executable functions as expected. Take the following two

How to call a constant as a function name?

随声附和 提交于 2021-02-18 22:59:13
问题 In PHP, you can call functions by calling their name inside a variable. function myfunc(){ echo 'works'; } $func = 'myfunc'; $func(); // Prints "works" But, you can't do this with constants. define('func', 'myfunc'); func(); // Error: function "func" not defined There are workarounds, like these: $f = func; $f(); // Prints "works" call_user_func(func); // Prints "works" function call($f){ $f(); } call(func); // Prints "works" The PHP documentation on callable says: A PHP function is passed by

Passing list of arbitrary function arguments in Haxe

喜夏-厌秋 提交于 2021-02-18 22:44:29
问题 In ActionScript I can use ... in a function declaration so it accepts arbitrary arguments: function foo(... args):void { trace(args.length); } I can then call the function passing an array: foo.apply(this, argsArray); I'd like to call the function with arguments of unknown type and count. Is this possible in Haxe? 回答1: According to the Haxe documentation, you can use a Rest argument: If the final argument of a macro is of type Array<Expr> the macro accepts an arbitrary number of extra

Is there a way to find performance of individual functions in a process using perf tool?

安稳与你 提交于 2021-02-18 22:25:50
问题 I am trying to get performance of individual functions within a process. How can I do it using perf tool? Is there any other tool for this? For example, let's say, main function calls functions A , B , C . I want to get performance of main function as well as functions A,B,C individually . Is there a good document for understating perf source code? Thank you. 回答1: What you want to do is user-land probing. Perf can only do part of it. Try sudo perf top -p [pid] and then watch the scoreboard.

Converting Json Object array Values to a single array

坚强是说给别人听的谎言 提交于 2021-02-18 19:32:39
问题 Good day I am trying to use an autocomplete jquery framework.. buy my problem is how can i get my objects either from a json file or just a quick typed json object like the below and get all the Object.values(arry) to a single array like below.. ["samue", "anthon", "Harmony", "Johnson"] and must be an array.. because auto complete frameworks only works with arrays const myobj = [ { "name": "samuel", "surname": "anthony" }, { "name": "Harmony", "surname": "Johnson" } ] const file = "json/user