- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我试图在 PHP 中找到一个关于可链接 OOP 对象的很好的介绍,但还没有任何好的结果。
这样的事情怎么办?
$this->className->add('1','value');
$this->className->type('string');
$this->classname->doStuff();
甚至:$this->className->add('1','value')->type('string')->doStuff();
非常感谢!
最佳答案
关键是在每个方法中返回对象本身:
class Foo {
function add($arg1, $arg2) {
// …
return $this;
}
function type($arg1) {
// …
return $this;
}
function doStuff() {
// …
return $this;
}
}
返回对象本身的每个方法都可以用作方法链中的中间体。参见 Wikipedia’s article on Method chaining了解更多详情。
关于PHP 面向对象 : Chainable objects?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2929928/
我正在尝试制作一个简单的 jQuery 插件。我想像这样调用它的链接方法: $("#div").myPlugin({ /* options */ }).add(".span", { /
我试图在 PHP 中找到一个关于可链接 OOP 对象的很好的介绍,但还没有任何好的结果。 这样的事情怎么办? $this->className->add('1','value'); $this->cl
我想创建一个 python shell 脚本 myscript.py,它可以将输出提供给管道或接收管道的输入,不止一次。例如。 $ myscript.py |脚本.py |我的脚本.py ... 下面
在 Cypress 更新 9.0.0 后,出现以下错误 参数类型字符串不可分配给参数类型 keyof Chainable... 类型字符串不可分配给类型 "and"| “作为” | “模糊” | “检
JS新手问题在这里: 假设我有一些简单的字符串操作方法,比如这些愚蠢的例子: var prepend = function(str) { return 'foo ' + str }; var ex
我是 JavaScript 和测试的新手。直到最近,我才写了人生中的第一次测试。我指的是“Chai.js”文档,它说: The assert style is very similar to node
我是 Typescript 的新手,虽然我认为我了解大部分内容,但我不明白的是为什么我不能对具有 Cypress.Chainable 类型的值使用标准 JS 方法。 例如: const chained
我看到了这个on a blog today ,我想,终于! Rails 会有类似 HQL 的内容或Linq 。嗯,或者不是。我找不到任何关于此的信息。 我真正想知道的是:我是否能够忘记表的名称并仅使用
我是一名优秀的程序员,十分优秀!