Questions tagged [chaining]

Chaining is an object-oriented programming technique where methods return the object on which they were called so that another method may be called on the same object, thus forming a method chain.

1000 questions
9
votes
2 answers

Chain-calling member functions off a constructor of a named object

First, I'm NOT talking about c++11 constructor chaining aka constructor delegation. Class member functions can return a reference to itself (the class) so function calls can be chained. (Such as how the cout << operator works to allow chain…
user1902689
  • 1,655
  • 2
  • 22
  • 33
9
votes
1 answer

Resource garbage collected too early

I've created a PHP extension with SWIG and everything works fine, but I'm observing some strange garbage collection behavior when chaining method calls. For example, this works: $results = $response->results(); $row =…
Ed Mazur
  • 3,042
  • 3
  • 21
  • 21
9
votes
3 answers

Chaining 'bind' and 'call' in JavaScript?

When I reading this answer, find var g = f.call.bind(f);. I can't understand this with my first sight. So does it has some direct meaning, and has some appropriate usage scenarios? And further when you using call(or apply) or bind or both in…
2hu
  • 309
  • 2
  • 6
9
votes
2 answers

What patterns are there for passing state through a chain of promises in Javascript?

I'm trying to learn a little about Node and asynchronous programming. I read about Promises and have made an attempt at using them in a small project that copies posts for a user from Service A to Service B. I am having some trouble understanding…
Andy Stanton
  • 195
  • 1
  • 9
9
votes
4 answers

How to implement method chaining?

In C# how does one implement the ability to chain methods in one's custom classes so one can write something like this: myclass.DoSomething().DosomethingElse(x); etc... Thanks!
Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
9
votes
4 answers

In-place function to remove an item using index in Python

Just noticed that there is no function in Python to remove an item in a list by index, to be used while chaining. For instance, I am looking for something like this: another_list = list_of_items.remove[item-index] instead of del…
Jikku Jose
  • 18,306
  • 11
  • 41
  • 61
9
votes
2 answers

Using && in subprocess.Popen for command chaining?

I'm using subprocess.Popen with Python, and I haven't come across an elegant solution for joining commands (i.e. foobar&& bizbang) via Popen. I could do this: p1 = subprocess.Popen(["mmls", "WinXP.E01"], stdout=subprocess.PIPE) result =…
user1260503
9
votes
4 answers

Why are parentheses needed in constructor chaining?

Why do expressions that use the new keyword need parentheses in order to be utilized in chained execution? In AS3, for example, you don't need parentheses. In PHP is this a stylistic aid for the interpreter or is there a bigger reason that I'm not…
Mark Fox
  • 8,694
  • 9
  • 53
  • 75
8
votes
2 answers

jQuery chaining

I don't think I'm correctly understanding jQuery chaining. I'm looping through an array and trying to add div elements to my wrapper CSS class with each div element having a class of 'click' and custom css top and left attributes, like this:…
CJD
  • 782
  • 3
  • 10
  • 20
8
votes
1 answer

C# pipelined function array signature

Does c#'s type system have the ability to specify a function that takes an enumerable number of functions which commute to form a pipeline? The effect would be similar to chaining, but instead of var pipeline = a.Chain(b).Chain(c) one could…
William
  • 410
  • 3
  • 10
8
votes
3 answers

Prototype chaining in JavaScript

I'm reading a book called JavaScript patterns but there's one part where I think the guy is confusing. The guy actually led up in the book to the klass design pattern, where he developed it piece by piece. He first he presents the problem: function…
JohnMerlino
  • 3,900
  • 4
  • 57
  • 89
8
votes
6 answers

How to use multiple .find() after selector in jquery chaining?

Basically what the title says - I'm wondering if there's a way to use .find() on the same jQuery selector multiple times. Or maybe using .find() more than once isn't the right way to do this? Here's what I'm trying to accomplish: HTML
daviddorsey4
  • 122
  • 1
  • 10
8
votes
6 answers

Chain custom javascript functions

After searching for quite some time, I still haven't found what I'm looking for. There's a fair amount of examples that either require creating a new instance, or only have functions that don't return anything (which means the problem can be solved…
KJdev
  • 723
  • 1
  • 9
  • 20
8
votes
2 answers

How can I sequentially chain promises using bluebirdjs?

Promise.all() doesn't guarantee that promises will be resolved in order. How can this be done?
redgeoff
  • 3,163
  • 1
  • 25
  • 39
8
votes
7 answers

In C#, what is the best/accepted way of doing constructor chaining?

Given the following class: public class MyClass { private string _param; public MyClass () { _param = string.Empty; } public MyClass (string param) { _param = param; } } I am torn apart between two ways…
Stécy
  • 11,951
  • 16
  • 64
  • 89