Javascript Perl

Doing common things for Perl developers on Javascript (II)

From Perl to Javascript relearning.

Perl allows us to bless any reference into any being an object of any class, this is not a good practice always, but can become handy on corner cases, here is how is done in Perl:

sub bless_into_class {
    my $class = shift;
    bless {}, $class;
my $object = bless_into_class( 'MY::Class' );

And the JS equivalent:

function create_object_of_class(input_class) {
    return Object.create(input_class.prototype);
let new_object = create_object_of_class(my_class);

By sergiotarxz

I am a software developer with high interest on free software.

Leave a Reply

Your email address will not be published. Required fields are marked *