Fundamentals of cross-platform development

When developing for different platforms, the most common problem we have to face is sharing the common parts of a component while providing different implementations for details that are platform-specific. We will now explore some of the principles and the patterns to use when facing this challenge.

Runtime code branching

The most simple and intuitive technique for providing different implementations based on the host platform is to dynamically branch our code. This requires that we have a mechanism to recognize at runtime the host platform and then switch dynamically the implementation with an if…else statement. Some generic approaches involve checking global variables that are available only on Node.js ...

Get Node.js Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.