UNPKG

prototypes

Version:

Some common prototypes for node.js: string.startsWith(), object.countProperties() and more. Facilities for functional programming with objects: object.forEach(), object.filter(). Functions are added safely using Object.defineProperty().

27 lines (22 loc) 394 B
'use strict'; /** * Extend a prototype with properties. * (C) 2013 Alex Fernández. */ /** * Define new prototype functions as properties. */ exports.addProperties = function(original, extension) { for (var key in extension) { if (original.hasOwnProperty(key)) { continue; } Object.defineProperty(original, key, { value: extension[key], writable: true, }); } };