Created
June 25, 2021 13:31
-
-
Save sivaprabug/b4fc4e12e87374dc515251f680a59acc to your computer and use it in GitHub Desktop.
Backbonejs triger the functionality with parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<title>Event On Example</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> | |
<script type="text/javascript"> | |
//Here creating an object 'myVal' and extending with Backbone.Events method | |
var myVal = _.extend({ name: 'Welcome to JavaTpoint' }, Backbone.Events); | |
// The on() method will bind callback function to an object and invoked whenever an event triggers | |
myVal.on('myFunc', function (param1) { | |
document.write("The triggered value is: "); | |
if ((param1 === undefined) || (param1 === "NULL") || (param1 === "")) { | |
param1 = 200; | |
} | |
document.write(this.name + " " + param1 + "<br><br>"); | |
}); | |
//It triggers the 'myFunc' event on object 'myVal' | |
myVal.trigger('myFunc', param1 = 10); | |
myVal.trigger('myFunc', 30); | |
myVal.trigger('myFunc',"NULL"); | |
myVal.trigger('myFunc',""); | |
myVal.trigger('myFunc',"tette"); | |
myVal.trigger('myFunc'); | |
myVal.trigger('myFunc', 20); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment