The Backbone.js noConflict Utility is used when we want the Backbone object as its original value. We can use the return value of the Backbone of this function as a reference to the Backbone.
Syntax:
var backbone = Backbone.noConflict() ;
Parameter: This Function doesn't take any parameter.
Example 1: In this example, we will illustrate Backbone.js noConflict Utility. We will gain the original value of Backbone.js with the help of conflict.
<!DOCTYPE html>
<head>
<title>BackboneJS noConflict Utility</title>
<script src=
"https://code.jquery.com/jquery-2.1.3.min.js"
type="text/javascript">
</script>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js"
type="text/javascript">
</script>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"
type="text/javascript">
</script>
</head>
<body>
<h1 style="color: green;">
GeeksforGeeks
</h1>
<h3>BackboneJS noConflict Utility</h3>
<script type="text/javascript">
this.Backbone = {
"Hello": "Hello this is not original backbone value"
, VERSION: '1.1.0'
}
</script>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"
type="text/javascript">
</script>
<script>
var newbackbone = Backbone.noConflict();
console.log(Backbone)
document.write(Backbone["Hello"], `
${Backbone['VERSION']}<br>`);
document.write("Original value of backbone is ",
newbackbone.VERSION);
</script>
</body>
</html>
Output:
Example 2: In this example, we will use the return original value of Backbone and use its return value reference and create a new Model with it.
<!DOCTYPE html>
<head>
<title>BackboneJS noConflict Utility</title>
<script src=
"https://code.jquery.com/jquery-2.1.3.min.js"
type="text/javascript">
</script>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js"
type="text/javascript">
</script>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"
type="text/javascript">
</script>
</head>
<body>
<h1 style="color: green;">
GeeksforGeeks
</h1>
<h3>BackboneJS noConflict Utility</h3>
<script type="text/javascript">
var newbackbone = Backbone.noConflict();
var model = newbackbone.Model.extend({
initialize: function () {
document.write(
"This is written by reference Backbone");
}
});
var temp = new model();
</script>
</body>
</html>
Output:
Reference: https://backbonejs.org/#Utility-Backbone-noConflict