我正在阅读一本JavaScript书籍,我正在阅读如何通过原型扩展JavaScript数组的数组功能,然后我来到这个我无法理解的例子,并且没有深入解释它,并且我无法理解那:
Array.prototype.some_function = function(){
var args = this.some_function.arguments; // 1
var args_length = this.some_function.arguments.length; // 2
...
} // some_function
Run Code Online (Sandbox Code Playgroud)
在这里我能够访问参数,但我不知道这是如何工作的,这意味着这是指我们调用此方法的对象(在此上下文中的数组),然后some_function引用该对象的属性,对我们正在实现的函数意味着什么,但是然后参数不是该函数的静态属性,那么它是如何工作的?它只适用于调用上下文,我不能将它用于其他人ex: -
this.some_other_function.arguments // gives error
Run Code Online (Sandbox Code Playgroud) 我的gen_server包含这样的方法:
handle_call(error, From, State) ->
io:format("Inside the handle_call error~n"),
1/0.
Run Code Online (Sandbox Code Playgroud)
它提供start
(非start_link
)功能:
start() ->
gen_server:start({local, ?MODULE}, ?MODULE, [], []).
normal_call() ->
gen_server:call(?MODULE, {normal}).
error_call() ->
gen_server:call(?MODULE, error).
Run Code Online (Sandbox Code Playgroud)
我start
从shell 调用函数:
c(some_module).
some_module:start().
Run Code Online (Sandbox Code Playgroud)
然后我调用终止服务器进程的错误调用,因为除零错误,但它也终止了shell(调用进程).我不明白为什么?它们没有链接但仍然使用新的pid重新启动shell.这是gen_server的预期行为,还是我做错了什么?
更新:它仍然无法正常工作,以帮助我发布完整的代码.
-module(some_test).
-behaviour(gen_server).
-compile(export_all).
%% api functions, can be directly used by the user
start() ->
gen_server:start({local, ?MODULE}, ?MODULE, [], []).
normal_call() ->
gen_server:call(?MODULE, normal, infinity).
error_call() ->
gen_server:call(?MODULE, error, infinity).
%% service specific function shoule not be call directly
init(_) ->
io:format("Inside …
Run Code Online (Sandbox Code Playgroud)