我正在观看视频,解释laravel的IoC容器的基础知识,而且我无法理解这段代码的作用.具体来说,我不理解UserRepository类的构造函数中的参数.我没有太多运气在php网站上找到这种语法的例子.
<?php
class UserRepository {
protected $something;
public function __construct(Something $something)
{
$this->something = $something;
}
}
class Something {}
?>
Run Code Online (Sandbox Code Playgroud) 这段代码在做什么?它是如何执行的?什么是x等于?
另一种有用的高阶函数类型修改了它给出的函数值:
function negate(func) {
return function(x) {
return !func(x);
};
}
var isNotNaN = negate(isNaN);
show(isNotNaN(NaN));
Run Code Online (Sandbox Code Playgroud)