method-chaining

Chaining Static Methods in PHP?

Is it possible to chain static methods together using a static class? Say I wanted to do something like this: $value = TestClass::toValue(5)::add(3)::subtract(2)::add(8)::result(); . . . and obviously I would want $value to be assigned the number 14. Is this possible? Update: It doesn't work (you can't return "self" - it's not an ins...

Javascript Window.Onload Function Chaining

Just for the sake of experimentation, I've been trying to determine different ways to non-destructively chain window.onload functions in a web browser. This is the idea of what I have so far: var load = window.onload; var newFunction = function(){ alert("ha!"); } window.onload = function(){ load(); newFunction(); } The pro...

Has jQuery taken a backwards approach to method chaining?

Is it just me who find the following code intrinsically backwards? I am using this posting as a reference. // create the inner div var $inner = $("<div>inner</div>") // append it to a new outer div .appendTo("<div>outer</div>") // next change the jQuery chain to the "outer" div .parent() // append the outer div to...

is there some dojo.fx.sleep function to use within a dojo.fx.chain animation?

I would like to fadeIn a node over one second. Then leave it on for 10 seconds. Then fadeOut for another 3 seconds. One way of chaining this would be as follows: dojo.fx.chain([ dojo.fadeIn({node:myNode, duration:1000}), // fading in for 1 second dojo.fadeIn({node:myNode, duration:10000}), // this does nothing for 10 seconds ...

Using HtmlTextWriter to Render Server Controls?

I'm writing the RenderContents() method of my ASP.NET server control. The method uses an HtmlTextWriter object to render the output content. For the control I'm writing, using the HtmlTextWriter's methods seems like it will require a lot of lines of code to open and close every tag and add every attribute to the stream. In the end I feel...

Why doesn't this associated create call work?

I've got a User model that has many Items. A Rating belongs to a User and an Item. In the DB, I have set ratings.user_id to be not NULL. when I am creating an Item, I would like to do this: def create current_user.items.create(params[:item]).ratings.create(params[:rating] redirect_to items_path end However, this balks wi...

Functional style C# API design (returning function parameter augmented with calculation result)

Hi, There is a question regarding usage of functional programming techiques in C# code. Example Let we have interface interface IGraph { /*contains vertices and edges*/} Suppose we need to layout graph's vertices (assign Point to each vertex). interface ILayoutInfo { Point GetVertexPoint(vertex); } Simple layout route can have ...

Method chaining + inheritance don't play well together?

Consider: // member data omitted for brevity // assume that "setAngle" needs to be implemented separately // in Label and Image, and that Button does need to inherit // Label, rather than, say, contain one (etc) struct Widget { Widget& move(Point newPos) { pos = newPos; return *this; } }; struct Label : Widget { Label& setTex...

JavaScript Object Method Chaining: useful?

So... messing around in JavaScript with an idea that's new to me, having methods of an Object return the Object of which they are methods; this then leads to chainability. My question, then: how can this be useful? I threw this together to test the fundamental workings: <script> MathChain = function() { this.pass = function() ...

Chaining selectors in jQuery

I'm a guy used to mootools' way of chaining selectors, and I can't seem to find anywhere how to do the same in jQuery. Suppose I have a select element in the selectObj variable. What I need is to get the last option in that select. In mootools I would have done something like: var option = $(selectObj).getElement('nth-child(last)') Ca...

Can Eclipse generate method-chaining setters

I'd like to generate method-chaining setters (setters that return the object being set), like so: public MyObject setField (Object value) { this.field = value; return this; } This makes it easier to do one-liner instantiations, which I find easier to read: myMethod (new MyObject ().setField (someValue).setOtherField (someOthe...

How to chain AJAX calls in Rails? A series of calls to be executed, depending on the result of the first call.

I've a AJAX call, that pulls some initial data. Based on this data, I want to fire a series of AJAX calls, updating different parts of the page. It can be done using JS, with the XMLHttpRequest and onreadystatechange, checking for the status. If the first call is done and the response is 200, I can just fire a series of AJAX calls. H...

Method chaining + inheritance don’t play well together? (Java)

This question has been asked in a C++ context but I'm curious about Java. The concerns about virtual methods don't apply (I think), but if you have this situation: abstract class Pet { private String name; public Pet setName(String name) { this.name = name; return this; } } class Cat extends Pet { public Cat catchMi...

Method chaining - why is it a good practice, or not?

Method chaining is the practice of object methods returning the object itself in order for the result to be called for another method. Like this: participant.addSchedule(events[1]).addSchedule(events[2]).setStatus('attending').save() This seems to be considered a good practice, since it produces readable code, or a "fluent interface"....

PHP Method Chains - Reflecting?

Is it possible to reflect upon a chain of method calls to determine at what point you are in the chain of calls? At the very least, is it possible to discern whether a method is the last call in the chain? $instance->method1()->method2()->method3()->method4() Is it possible to do the same using properties that return instances of obje...

Is there a nice simple & elegant way to make ICollection more fluent in C#?

Example: I would like to have the Add method of ICollection of a custom collection class to implement method chaining and fluent languages so I can do this: randomObject.Add("I").Add("Can").Add("Chain").Add("This"). I can think of a few options but they are messy and involves wrapping ICollection in another interface and so forth. ...

JavaScript method chaining challenge

(This question is not really restricted to the language so please feel free to submit solution in other languages too.) I was just wondering if it would be possible to write something like this in JavaScript: // Wait 3 seconds and then say our message in an alert box wait(3).then(function(){alert("Hello World!");}); Where the traditi...

What determines the execution order of methods in jQuery chains?

HTML Code <div id="foo"> <h1>foo</h1> <p>Pellentesque habitant morbi tristique.</p> </div> <div id="bar"> <h1>bar</h1> </div> jQuery Code $('#bar').click(function () { $('#foo p').hide('slow').appendTo('#bar').show('slow'); }) Expected Result When #bar is clicked hide the p element in #foo append p to #bar show p...

How to attach an event to onSubmit event of form with chaining earlier attached methods as well?

Actaully my application is having hundreds of pages. Now i have to attach an event 'disablePage' on onSubmit of form. I don't want to go to each and every page and write: <form name="frmname" onSubmit="disablePage();"> What i am doing right now is:- excerpt from common.js file; [ included in all pages ] /* we have to attach 'attachF...

System.out.println - Is this method chaining in Java?

I am wondering about the the following piece of Java code: "System.out.println". I am right about this: "System" is a static class. ".out" is a method of class "System". This is the bit I am slighty confused about ".println"-- what class / object is this a method of? Also, is this concept known as "method chaining"? Thanks GF ...