Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@microsoft/dynamicproto-js

Package Overview
Dependencies
Maintainers
3
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@microsoft/dynamicproto-js

Microsoft Dynamic Proto Utility

  • 2.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created

What is @microsoft/dynamicproto-js?

@microsoft/dynamicproto-js is a JavaScript library that allows developers to dynamically define and extend prototype methods for JavaScript classes. This can be particularly useful for creating flexible and maintainable code, especially in scenarios where you need to add or override methods at runtime.

What are @microsoft/dynamicproto-js's main functionalities?

Dynamic Method Definition

This feature allows you to dynamically define methods on a class prototype. In this example, `myMethod` is added to the prototype of `MyClass` at runtime.

const dynamicProto = require('@microsoft/dynamicproto-js');

class MyClass {
  constructor() {
    dynamicProto(MyClass, this, function (_self) {
      _self.myMethod = function () {
        console.log('Dynamic method called');
      };
    });
  }
}

const instance = new MyClass();
instance.myMethod(); // Output: Dynamic method called

Method Overriding

This feature allows you to override existing methods in a class. In this example, `myMethod` in `DerivedClass` overrides the method in `BaseClass` and also calls the base method.

const dynamicProto = require('@microsoft/dynamicproto-js');

class BaseClass {
  myMethod() {
    console.log('Base method called');
  }
}

class DerivedClass extends BaseClass {
  constructor() {
    super();
    dynamicProto(DerivedClass, this, function (_self, base) {
      _self.myMethod = function () {
        console.log('Derived method called');
        base.myMethod.call(_self);
      };
    });
  }
}

const instance = new DerivedClass();
instance.myMethod(); // Output: Derived method called
                      //         Base method called

Other packages similar to @microsoft/dynamicproto-js

Keywords

FAQs

Package last updated on 11 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc