草庐IT

Chaining

全部标签

javascript - 如何链接javascript日期函数

有没有办法链接javascript日期函数?例如,我想这样:vard=newDate().setMinutes(0).setSeconds(0).setMilliseconds(0);此语法因错误而中断:(newDate).setMinutes(0).setSecondsisnotafunction我知道我可以做到:vard=newDate();d.setMinutes(0);d.setSeconds(0);d.setMilliseconds(0);但这感觉冗长和繁琐。有没有更好的办法? 最佳答案 您可以使用setMinutes方法

javascript - 使用 jQuery 的动态 AJAX promise 链

我的AJAX调用是在for循环内构建的。它们需要有序(同步)。我如何使用jQuery链接它们?vararray=['One','Two','Three'];vararrayLength=array.length;for(vararrayCounter=0;arrayCounter 最佳答案 使用for的解决方案:vararray=['One','Two','Three'];varid=array[0];vardata=getData(id);for(vari=1;i顺便说一下,如果你使用了合适的promises库,比如bluebir

javascript - 是否有一种首选的方式来格式化 jQuery 链以使其更具可读性?

给定以下示例代码,该代码克隆表格行,设置一些属性,然后将其附加到表格:$("#FundTable").append(objButton.parents("tr").clone().find(".RowTitle").text("Row"+nAddCount).end().find(".FundManagerSelect").attr("id","FundManager"+nAddCount).change(function(){ChangeFundRow();}).end().find(".FundNameSelect").attr("id","FundName"+nAddCount)

php - 具有不同返回值的函数链接?

是否可以根据上下文(如何使用返回值)让方法返回不同的值?例如,一个方法是否可以在与箭头运算符一起使用以调用另一个方法(即链接方法调用)时返回$this,但在未以这种方式使用返回值时返回标量?案例一:$result=$test->doSomething1();//returns4//$resultreturns4案例二:$result=$test->doSomething1()->doSomething2();//doSomething1()returns$this//doSomething2()returns8有没有办法执行这样的行为? 最佳答案

php - OOP 方法链接可选返回

此时,假设我有这样一个类:classSentence{__construct($content){$this->content=$content;}publicfunctiongrab_word($num){$words=explode("",$this->content);return$words[$num+1];}}所以给定的接口(interface)将允许我创建一个新句子,然后我可以调用grab_word()类方法来获取句子中的单词:$sentence=newSentence("Loremipsumdolorsitamet");echo$sentence->grab_word(2

php - 通过类链接的全局 PHP 函数

是否可以通过对象/类链接所有PHP函数?我有这个想法,我想象它是这样的:$c=newChainer();$c->strtolower('StackOverFlow')->ucwords(/*thevaluefromthefirstfunctionargument*/)->str_replace('St','B',/*thevaluefromthefirstfunctionargument*/);这应该产生:Backoverflow谢谢。 最佳答案 看看:http://php.net/manual/en/language.oop5.m

php - "Array chaining"的最佳解决方案

对于我的项目,我编写了一个小型配置类,它从.ini文件加载其数据。它覆盖了神奇的__get()方法,以提供对(只读)配置值的简化访问。示例config.ini.php:;[General]auth=1user="halfdan"[Database]host="127.0.0.1"我的配置类(单例模式-此处简化)如下所示:classConfig{protected$config=array();protectedfunction__construct($file){//Preservesections$this->config=parse_ini_file($file,TRUE);}pu

php - 是好是坏?为 PHP 带来 "Function Chaining"功能

按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭11年前。因此,我在想一种可以将方法链接引入具有内置全局函数的PHP的方法是从F#“借用”|>(管道)运算符。它会将左侧的结果通过管道传递给右侧函数的第一个参数。当然,PHP将不得不重新审视其某些函数的参数顺序。这将允许你写:functionStrManip($val){returnstr_repeat(strtolower(trim($val)),2);}像这样

php - 如何在 PHP5 : $this->foo->bar->baz() 中链接对象

如何在PHP5类中创建链接对象?示例:$myclass->foo->bar->baz();$this->foo->bar->baz();Not:$myclass->foo()->bar()->baz();另请参阅:http://www.talkphp.com/advanced-php-programming/1163-php5-method-chaining.html 最佳答案 实际上这个问题是模棱两可的......对我来说这个@Geo的回答是正确的。你(@Anti)说的可能是composition这是我的例子:what=$what

PHP 面向对象 : Method Chaining

我有以下代码,$value);}publicstaticfunctiondraw(){self::$params;}}$test=Templater::assign('key','value');$test=Templater::draw();print_r($test);如何更改此脚本以便我可以使用它?$test=Templater::assign('key','value')->assign('key2','value2')->draw();print_r($test); 最佳答案 您不能使用MethodChaining使用静态