0

I'm doing firebase project these days, and i got a question about something.

var citiesRef = db.collection("cities");
citiesRef.where("state", ">=", "CA").where("population", ">", 100000)

Those where() are stick together after dot and i have no idea. How can i make function or class like that? I don't even know how to search !

I tried to make classes and unnamed functions but it doesn't work.

If i get to know about it, it'll be very useful for me. I really want to know.

Please help please

6
  • Your question is very unclear, can you please make your question self explainable by adding some examples instead of describing about it? Commented Dec 11, 2018 at 3:20
  • i want to make like this function foo() {} foo().foo().foo() Commented Dec 11, 2018 at 3:25
  • 2
    You can search about chaning methods in javascript Commented Dec 11, 2018 at 3:27
  • 1
    In Javascript this is called "method chaining". Commented Dec 11, 2018 at 3:28
  • 1
    Please refer the link for more details. schier.co/blog/2013/11/14/method-chaining-in-javascript.html Commented Dec 11, 2018 at 3:47

1 Answer 1

2

This is something akin to the Builder Pattern. The idea is to return the object after appending a condition.

Example code (language agnostic):

def where(condition){
    self.appendCondition(condition)
    return self  // Important part
}

The return self enables to chain methods on the same object. Each one returns itself with the new condition appended.

Sign up to request clarification or add additional context in comments.

1 Comment

If you feel the answer helps you and may help others, please consider marking it as accepted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.