Binding Objects with Functions in ECMAScript 2016

The development ECMAScript 2016 has already started. One of the coming new capabilities will allow us to bind a function to specific object in order to be notified of changes that take place in that object. This capability is already supported in Google Chrome!

This following code sample shows this capability in action. You can check it out by running this code sample in Google Chrome and check the console.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <script>
        function observer(changes) {
            console.log("### inside observer ###");
            changes.forEach(function(change){
                        console.log(change.type, change.name, change.oldValue);
                    }
            );
        }

        var ob = new Object();
        ob.id = 12321;
        ob.name = "david";
        ob.average = 87;

        window.Object.observe(ob,observer,['delete','update']);

        ob.average = 90;
        ob.name = "david dahan";

        Object.deliverChangeRecords(observer);

        ob.average = 92;
        ob.name = "david dahan junior";
        ob.average = 90;

        Object.deliverChangeRecords(observer);

        ob.id = 123123123;
        delete ob.name;

        Object.deliverChangeRecords(observer);

        Object.unobserve(ob,observer);

        ob.average = 100;

        Object.deliverChangeRecords(observer);

    </script>
</body>
</html>

The following video clip overviews the execution of this code sample and explains it step by step. I strongly believe it will assist you with understanding this topic.

Share:

The Visitor Design Pattern

The Visitor Design Pattern

The visitor design pattern allows us to add operations to objects that already exist without modifying their classes and without extending them.

What are Anti Patterns?

Anti Patterns

Unlike design patterns, anti patterns just seem to be a solution. However, they are not a solution and they cause additional costs.

Virtual Threads in Java Professional Seminar

Virtual Threads in Java

The use of virtual threads can assist us with improving the performance of our code. Learn how to use virtual threads effectively.

NoSQL Databases Courses, Seminars, Consulting, and Development

MongoDB Design Patterns Meetup

The use of MongoDB involves with various cases in which we can overcome performance issues by implementing specific design patterns.

image of woman and database

Record Classes in Java

Learn how to define record classes in Java, and when to use record classes in your code. Stay up to date with the new Java features.

Accessibility | Career | Conferences | Design Patterns | JavaScript | Meetups | PHP | Podcasts | Python | Self Learning

Teaching Methodologies | Fullstack | C++ | C# | CSS | Node.js | Angular | Java | Go | Android | Kotlin | Swift | Academy

Front End Development | Scala | Architectures | Cloud | Big Data | Internet of Things | Kids Learn Programming

The Beauty of Code

Coding is Art! Developing Code That Works is Simple. Develop Code with Style is a Challenge!

Skip to content Update cookies preferences