Skip to Main Content
Hack 与HHVM 权威指南
book

Hack 与HHVM 权威指南

by Owen Yamauchi
March 2017
Beginner content levelBeginner
247 pages
3h 55m
Chinese
China Machine Press
Content preview from Hack 与HHVM 权威指南
178
7
return
<span id={$this->getID()}>Hello world</span>;
}
}
管理类属性
正如我们现在所看到的,
XHPHelpers
的属性传递逻辑会对类属性特殊对待。这是
因为
DOM
节点的类属性并不像其他的属性:从语义上来说,它的值是一组值,而
不是单一值。
XHPHelpers
内联地提供了两个方法用于这两种语义:
addClass()
conditionClass()
addClass()
一个字符串作为实参,并且把它添加到对象的类属性上。(当然,对象的
类必须间接或者直接地声明类属性。)它确定这个属性值的存在,并且附加的新值会使
用空格进行分隔:
class :ui:drop-shadow-box
extends :x:element {
attribute
:div;
protected function
render(): XHPRoot {
$div = <div />;
$div->addClass('drop-shadow');
$div->appendChild($this->getChildren());
return
$div;
}
}
conditionClass()
有两个
实参:一个布尔型和一个字符串型。如果布尔型实参是真的话,
它将直接使用字符串实参调用
addClass()
7.4 XHP
最佳实践
HHVM
提供了语法,
Hack
类库提供了基础架构和
HTML
标记,但在这些基础之上构建
一个好的
UI
库是留给广大读者们的一个实践项目了。 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Reinventing the Organization for GenAI and LLMs

Reinventing the Organization for GenAI and LLMs

Ethan Mollick

Publisher Resources

ISBN: 9787111554844