Open In App

Fabric.js extend() Method

The extend() method is used to create a copy of all the properties of the source objects over the destination object and return the destination object. Do not clone or extend fabric.Object subclasses. This is mostly for internal use and has extra handling for fabricJS objects, it skips the canvas property in deep cloning.

Syntax:



extend(destination, source)

Parameters: This method accepts two parameters as mentioned above and described below:

Return Value: This method returns a copy of all of the properties of the source objects over the destination object, and return the destination object.



Example 1:




<!DOCTYPE html>
<html>
  
<head>
    <script src=
    </script>
  
    <script type="text/javascript" src=
    </script>
  
    <script type="text/javascript" src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
        var obj1 = {
            key1: 'Geeks',
        };
  
        var obj2 = {
            key2: 'GeeksforGeeks',
        };
  
        console.log(fabric.util
            .object.extend(obj1, obj2));
    </script>
</body>
  
</html>

Output:

{"key1": "Geeks", "key2": "GeeksforGeeks"}

Example 2:




<!DOCTYPE html>
<html>
  
<head>
    <script src=
    </script>
  
    <script type="text/javascript" src=
    </script>
    <script type="text/javascript" src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
        var obj1 = {
            key1: 'GFG', key2: 'gfg',
        };
  
        var obj2 = {
            key3: '5', key4: '10',
        };
  
        console.log(fabric.util
            .object.extend(obj1, obj2));
    </script>
</body>
  
</html>

Output:

{"key1": "GFG", "key2": "gfg", "key3": "5", "key4": "10"}

Article Tags :