dracoblue.net

process.mixin deprecated in nodejs

When you are using process.mixin within nodejs 0.1.33, you'll get the following message:

deprecation warning: process.mixin will
be removed from node-core future releases

That this function is not in process anymore, is correct. It has nothing to do with processes. That said, you may think if you really need process.mixin at all. This function is available to create a (deep) copy of an entire object and it's properties.

In my case, I wanted to keep the ability to extend a prototype of an object with an aspect like "Logging".

Thatswhy I called the function

extend and borrowed the implementation from jquery (also licensed under the terms of MIT).

Where to get this "extend"-function from? Option 1: Copy the process.mixin from nodejs 0.1.30 Option 2: Take extend from jquery and modify it so it fits nodejs Option 3: Copy the nodejs version of jquerys extend from my util.js :)

Now I can easily do:

extend(true, Controller.prototype, Logging.prototype)

and every new Controller will have the Logging features, too!

By the way, there's always the possibility to do

JSON.parse(JSON.stringify(obj))

if the object does not contain any functions or those are not important to you.

In javascript, jquery, node.js by
@ 03 Apr 2010, Comments at Reddit & Hackernews

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About