Katxupa
  • 👋Welcome to Katxupa Extension Library
  • Why Katxupa?
    • 🍻What makes Katxupa special?
    • ✨Key Features
  • Get a taste of Katxupa
    • 🍲Installation
    • 🍜Usage
      • 🍻Scope Functions
        • Function Selection
        • Distinctions
        • Functions
          • letIt
          • withIt
          • runIt
          • applyIt
          • alsoIt
          • takeIf and takeUnless
      • 😎Null Safety
        • TypeScript Null-Safety
        • Optional Chaining for JavaScript
      • ⏰Duration
      • ➖Reducer
      • 📏Range
      • 🏃‍♂️Result
      • 🤼Either
      • 🟰Compare
      • ⚔️Global Utility Functions
    • 🤌Dip Dive
      • Optional
      • Range
      • Duration
      • Reducer
      • Collections
        • Array
        • Set
  • 🙏Support
    • Source Code
    • ESLint Config
    • TypeScript Docs
    • Manuel Santos Linkedin
Powered by GitBook
On this page
  1. Get a taste of Katxupa
  2. Usage
  3. Scope Functions
  4. Functions

applyIt

applyIt(function(){ // do something here with this })

  • The context object is available as a receiver (this).

  • The return value is the object itself.

As applyIt returns the context object itself, we recommend that you use it for code blocks that don't return a value and that mainly operate on the members of the receiver object. The most common use case for applyIt is for object configuration. Such calls can be read as "apply the following assignments to the object."

const manuel = {name: "Manuel", age: 36};

manuel.applyIt(function () {
    this.name = "Manuel Santos";
    this.age++;
    (this as any)["country"] = "Portugal";
});
console.log(manuel)

Another use case for applyIt is to include applyIt in multiple call chains for more complex processing.

PreviousrunItNextalsoIt

Last updated 1 year ago

🍜
🍻