我有一个Javascript函数getCartProducts(),它通过AJAX获取一个JSON数组$.post(),返回一个值.我想让我的函数返回该值,但我不知道该怎么做.
这是我的功能:
function getCartProduct(id){
$.post('core/ajax/getCartProduct.ajax.php', {id: parseInt(id)}, function(data){
var result = data;
});
return result;
}
Run Code Online (Sandbox Code Playgroud)
我知道这不会起作用,因为te变量结果只在$.post()函数中有效,但我不知道如何直接得到它.
当我使用这段代码时:
#include <stdio.h>
int main(void){
int hi, hello;
hi = 1;
hello = 100;
printf("%d and %d", &hi, &hello);
printf("\nPress any key to exit...");
getch();
}
Run Code Online (Sandbox Code Playgroud)
它打印:
2358876 and 2358872
Press any key to exit
Run Code Online (Sandbox Code Playgroud)
但是当我定义变量hi并将它们hello分别定义为整数时,它会做它应该做的事情.为什么要打印这些奇怪的数字?
正如标题中所述:为什么您添加到界面的每个功能都必须公开?
在接口中声明的所有方法都必须是公共的; 这是界面的本质
如上面引用中所述,界面的性质是什么?
如何让一个类实现一个接口,另一个类扩展该类.为什么不能在扩展主类的类中定义必要的方法?
请注意:我确实知道如何使用接口,但我只是想知道为什么这些东西不可能预定义.