Questions tagged [chainable]

16 questions
22
votes
2 answers

How to make chainable function in JavaScript?

Lets imagine function like this: function foo(x) { x += '+'; return x; } Usage of it would be like: var x, y; x = 'Notepad'; y = foo(x); console.log(y); // Prints 'Notepad+'. I'm looking for a way to create function that's chainable with…
daGrevis
  • 19,600
  • 35
  • 95
  • 134
8
votes
3 answers

PHP OOP: Chainable objects?

I have tried to find a good introduction on chainable OOP objects in PHP, but without any good result yet. How can something like this be done? $this->className->add('1','value'); $this->className->type('string'); $this->classname->doStuff(); Or…
Industrial
  • 36,181
  • 63
  • 182
  • 286
5
votes
2 answers

How do I make this into a chainable jquery function?

My function returns a filtered (array) list of items based on the data attribute. I would like it if I could make this function chainable: $(document).ready(function (){ function filterSvcType (svcType) { var selectedServices =…
Amit Erandole
  • 10,436
  • 20
  • 60
  • 92
4
votes
1 answer

Symfony2: Sonata Admin: Chained selectors, sonata_type_model_reference

Has anyone ever implemented sonata_type_model_reference form type? I need to chain state and country relations, and I read on an slideshare that that is possible with sonata_type_model_reference, but I can't find any documentation of it. How to…
edrian
  • 4,377
  • 5
  • 26
  • 34
3
votes
2 answers

Ruby chainable method / array

How do I implement the '<<' to have the same behavior when used as a chainable method? class Test attr_accessor :internal_array def initialize @internal_array = [] end def <<(item) @internal_array << :a @internal_array << item …
Portela
  • 53
  • 5
3
votes
1 answer

Chainable, Promise-based Class Interfaces in JavaScript

I am writing a constructor in JavaScript that has the following properties: function WhizBang() { var promise; this.publicMethod_One = function publicMethod_One() { ... }; this.publicMethod_Two = function publicMethod_Two() { ... }; …
user1739757
2
votes
1 answer

Fluent async api with ES6 proxy javascript

So... I have some methods. Each method returns a promise. myAsyncMethods: { myNavigate () { // Imagine this is returning a webdriverio promise return new Promise(function(resolve){ …
2
votes
2 answers

Javascript - Create chainable functions without tainting everything

I'm kind of newbie on JS, but I've done my research on the subject and found no exhaustive answer. I'm using Angular JS for a project, and I have a service that expose some functions: var app = angular.module('myApp', []) app.service('mySrv',…
domokun
  • 2,995
  • 3
  • 27
  • 55
1
vote
3 answers

How do I make this jQuery plugin chainable?

Can anyone show me how to go about making this jQuery plugin chainable? The plugin limits text input into a field, and returns a remaining text count to the 2nd argument if passed in. Thanks. (function($) { $.fn.extend({ limit: function(limit,…
regan
  • 143
  • 1
  • 10
1
vote
1 answer

Cypress: Getting or returning elements using within() other elements

I have methods in my test code that uses within to find and access selectors. Mainly, it's because there are several blocks of code with identically named selectors, which I cannot change. But also because I find it more tidy than dealing with…
Hfrav
  • 901
  • 1
  • 6
  • 20
1
vote
2 answers

Ruby Array Chainables Combining Map & Inject

Is there a nice way to create a Ruby array chainable on the fly that combines map and inject? Here's what I mean. Let a be an array of integers, then to get all sums of 2 adjacent elements we can do: a.each_cons(2).map(&:sum) We can also get the…
1
vote
2 answers

Javascript Chainable Closure

Inspired by If Hemingway Wrote Javascript, I'm trying to write a chainable function closure with a private local variable. The intended behavior is: > chainableCounter() 0 > chainableCounter(1)(2)() 3 Here's my code: function chainableCounter(n) { …
Fried Brice
  • 831
  • 6
  • 18
0
votes
1 answer

Is it possible to provide default implementation of chainable trait methods?

The goal would be to have something similar to (playground): trait T { fn get_mutable_attribute(&mut self) -> &mut String; fn forwardable_append_attribute(mut self, new_value: &str) -> Self { let attribute =…
aeon
  • 33
  • 6
0
votes
3 answers

PHP methods return array and still be chainable

I'm quite sure this isn't possible but I'm really hoping its gonna be possible. i want to call my models in this way for instance $getAll = models\company::getInstance()->getAll("ID < 4") which is basicaly just class company extends _ { private…
WilliamStam
  • 214
  • 2
  • 12
0
votes
1 answer

IIFE chainable not returning correctly

(function (w, d, u) { /* Variable Conventions _*VAR*_ is html or class text*/ var wl = '^\\/t\\d+', ps = '^\\/post', pv = '\\/privmsg\\?.+(post|reply){1}(.*)?', _GROUP_ = null, i, _CLASS_ = "sceditor-button…
EasyBB
  • 4,644
  • 7
  • 40
  • 69
1
2