Skip to content
Related Articles
Open in App
Not now

Related Articles

Fabric.js extend() Method

Improve Article
Save Article
  • Last Updated : 31 Dec, 2020
Improve Article
Save Article

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

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!