
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
msff-constructor-overwrite
Advanced tools
Overwrite a constructor function in JavaScript.
Version 1.2.0 released in August 10, 2015 (CHANGELOG).
Travis CI:
This project is recommended to extend or rewrite constructor functions in javascript using a lightweight code.
This project is not recommended to give class inheritance feature to ES5/ES3 projects. In this case, we recommend to use
This project is available as npm package:
npm install --save msff-constructor-overwrite
If you're using TypeScript, you must also link the definitions files with TSD:
tsd link
var overwrite = require('msff-constructor-overwrite');
// overwrite(oldConstructor, newConstructor);
// overwrite(oldConstructor, newConstructor, propertyForOldConstructor);
The newConstructor will receive the prototype of oldConstructor. If
newConstructor already have a prototype, it'll be overwritten.
In addition, newConstructor will have the old constructor stored in
a static property named ___oldConstructor. You can use a custom name by
using the third argument.
var overwrite = require('msff-constructor-overwrite');
var Person = (function() {
function Person(name) {
this.name = name;
}
return Person;
})()
Person = overwrite(Person, function(firstName, lastName) {
this.name = [firstName, lastName].join(" ");
});
var me = new Person('Marcos', 'Filho')
// me.name => Marcos Filho
var overwrite = require('msff-constructor-overwrite');
var Person = (function() {
function Person(name) {
this.name = name;
}
return Person;
})()
Person = overwrite(
Person,
// You must name the constructor to extend
function Person_Extended(firstName, lastName) {
this.fullName = [firstName, lastName].join(" ");
// Calling the old constructor
Person_Extended.old.apply(this, arguments)
},
// By default the old goes on `___oldConstructor`
// Use the third parameter to overwrite the property
"old"
);
var me = new Person('Marcos', 'Filho')
// me.name => Marcos
// me.fullName => Marcos Filho
FAQs
Overwrite a constructor function in JavaScript
We found that msff-constructor-overwrite demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.