Skip to content

Instantly share code, notes, and snippets.

@shubhadeep
Created August 5, 2014 13:56
Show Gist options
  • Save shubhadeep/df877a3e07bd2ccc1039 to your computer and use it in GitHub Desktop.
Save shubhadeep/df877a3e07bd2ccc1039 to your computer and use it in GitHub Desktop.
Comparison of binding SAPUI5 button actions as in-line functions (closures) vs. binding the same instance (by function name). Compare the memory heap profile to see the difference in both cases.
/**
* Comparison of binding button actions as inline functions (closures)
* profile to see the difference in both cases.
* vs. binding the same instance (by function name). Compare the memory heap
*/
// Bind function expression (closure) - 1M times
(function (numButtons) {
var btn = new sap.m.Button({text: "hello"});
for(var i = 0; i < numButtons; i++) {
btn.attachPress(function (e) { console.log(e);});
}
btn.placeAt('content');
})(1000000);
// Bind named function - 1M times
(function (numButtons){
function pressed(e) {
console.log(e);
}
var btn = new sap.m.Button({text: "hello"});
for(var i = 0; i < numButtons; i++) {
btn.attachPress(pressed);
}
btn.placeAt('content');
})(1000000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment