Open In App

Fabric.js extend() Method

Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • destination: This parameter says where to copy to.
  • source: This parameter says where to copy from.

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:

Javascript




<!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:

Javascript




<!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"}


Last Updated : 31 Dec, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads