While developing a utility library for DOM manipulation, how can closures be employed to create interface methods while keeping some of the implementation details private?

  • Expose all implementation details in global scope
  • Use closures to create private variables and functions, exposing only necessary interface methods
  • Use global variables to store utility functions
  • Use anonymous functions for all DOM manipulation
Closures can be used to create private variables and functions within the library, allowing you to expose only the necessary interface methods while keeping implementation details private. Exposing all details in the global scope (option a) is not a good practice. Using global variables (option c) and anonymous functions (option d) do not provide the same level of encapsulation and privacy as closures.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *