Questions tagged [chainable]

19 questions
24
votes
3 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
  • 21,014
  • 37
  • 100
  • 139
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
  • 41,400
  • 69
  • 194
  • 289
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
  • 11,995
  • 23
  • 65
  • 103
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,501
  • 5
  • 31
  • 35
3
votes
2 answers

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){ …
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
2 answers

Cypress JS using multiple page objects in one method

i have been struggling with some logic about using multiple page objects in one method, i couldnt find any idea to use like that logic, for example; These are my methods in my page object called usersTable; get rolesAndStatusMenu() { return…
2
votes
1 answer

JavaScript/Typescript chainable function without class

I am trying to correctly code my chainable function in Typescript. Below is the code const sum = (val: number | undefined) => { let internal = Number(val); if (val) { return function sumup(_val: number | undefined) { if (_val…
Igor Shmukler
  • 1,742
  • 3
  • 15
  • 48
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
  • 3,013
  • 3
  • 29
  • 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
  • 305
  • 2
  • 15
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
  • 769
  • 7
  • 20
0
votes
1 answer

Creating nested JS maps dynamically via a loop

The following code creates a nested JS map. It works already: let a = data[0]; let b = data[1]; let c = data[2]; myMap.set(a, myMap.get(b) || new Map()); myMap.get(a).set(b, myMap.get(a).get(b) || new Map()); myMap.get(a).get(b).set(c,…
user16481310
0
votes
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…
user9347168
1
2