Fun with JavaScript inheritance

Post Syndicated from Anonymous original http://deliantech.blogspot.com/2014/06/fun-with-javascript-inheritance.html

One could say that JavaScript does not support native inheritance for OOP and could not be so wrong. JavaScript happened to be having one of the most powerful OOP I have ever seen 🙂
Something more, JavaScript does the inheritance trough a prototype chaining, which actually provides even more power than you can imagine.
See the following simple chaining example, that shows a chained inheritance (not the typical one-step prototype->object inheritance everyone knows):
~$ node
> a={}
{}
> b = Object.create(a)
{}
> c = Object.create(b)
{}
> a.test = 1
1
> a
{ test: 1 }
> b
{}
> c
{}
> c.test
1
> b.text=2
2
> b
{ text: 2 }
> b.test
1
> c.test
1
> c.text
2
> c
{}
So now you can see above how can we do a very easy but powerful chain of objects. Something more, that works for ANY object, including chaining BOTH the methods and the prototypes of the objects, so you can modify either the objects directly, or their prototypes and everything is inherited with a two-shadow priority model.
~$ node
> a=[1,2,3,4]
[ 1, 2, 3, 4 ]
> b=Object.create(a)
{}
> b
{}
> b[1]
2
> b.length
4
> b
{}
So now you can see that b is still (an empty) object but has behavior and properties like an array 🙂

Operator overloading with JavaScript

Post Syndicated from Anonymous original http://deliantech.blogspot.com/2014/06/operator-overloading-with-javascript.html

JavaScript happens to have an extremely powerful OOP tool-set that is quite unknown. I am surprised every day by the power and flexibility of it.
One of the things I didn’t knew is possible at all with JavaScript was operator overloading.
And this is understandable – JavaScript doesn’t have strict variable types. Therefore any type of polymorphism is very hard to be implemented, as it is bound to the object/variable types.
However, you can easily do polymorphism with JavaScript and as it happens, you can easily do operator overloading too 🙂
How that works?
It is really easy – JavaScript retrieve the value of an Object using the valueOf method. And every object has valueOf with the exception of few primitive types (as in Java and C++). Therefore you can use that to do operator oveloading.
Let me show you an example:
~$ node
> a={}
{}
> a == 3
false
> a.valueOf = function() { return 3 }
[Function]
> a == 3
true
> 
And the best is that you can do that to the prototype (or to the inherited object):
~$ node
> {} == 3
false
> Object.prototype.valueOf = function() { return 3 }
[Function]
> {} == 3
true
> 

New improved version of the node-netflowv9 module for Node.JS

Post Syndicated from Anonymous original http://deliantech.blogspot.com/2014/06/new-improved-version-of-node-netflowv9.html

As I have mentioned before, I have implemented a NetFlowV9 compatible library for decode of Cisco NetFlow version 9 packets for Node.JS.
Now I am upgrading it to version 0.1 which has few updates:
  • bug fixes (including avoidance of an issue that happens with ASR9k and IOS XR 4.3)
  • now you can start the collector (with a second parameter of true) in a mode where you want to receive only one call back per packet instead of one callback per flow (the default mode). That could be useful if you want to count the lost packets (otherwise the relation netflow packet – callback is lost)
  • decrease of the code size
  • now the module compiles the templates dynamically into a function (using new Function). I like this approach very much, as it creates really fast functions (in contrast to eval, Function is always JIT processed) and it allows me to spare loops, function calls and memory copy. I like to do things like that with every data structure that allows it. Anyway, as an effect of this, the new module is about 3 times faster with all the live tests I was able to perform

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

Node.js Removes Its CLA

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2014/06/11/nodejs-no-cla.html

I’ve had my disagreements with Joyent‘s management
of the Node.js project. In fact, I am
generally auto-skeptical of any Open Source and/or Free Software project
run by a for-profit company. However, I also like to give credit where
credit is due.

Specifically, I’d like to congratulate Joyent for making the right
decision today to remove one of the major barriers to entry for
contribution to the Node.js project: its CLA. In
an announcement
today (see section labeled “Easier Contribution”
, Joyent
announced Joyent no longer requires contributors to sign the CLA and
will (so it seems) accept contributions simply licensed under the
MIT-permissive license. In short, Node.js is, as of today, an
inbound=outbound
project.

While I’d prefer if Joyent would in addition switch the project
to the Apache License 2.0 — or even better, the Affero GPLv3 —
I realize that neither of those things are likely to happen. 🙂 Given that,
dropping the CLA is the next best outcome possible, and I’m glad it has
happened.


For further reading on my positions against CLAs, please see these two
older blog posts:

The collective thoughts of the interwebz