Skip to content

Instantly share code, notes, and snippets.

@marcustyphoon
Last active August 21, 2020 21:53
Show Gist options
  • Save marcustyphoon/2d18feb18656d65815333bd5628ae2d0 to your computer and use it in GitHub Desktop.
Save marcustyphoon/2d18feb18656d65815333bd5628ae2d0 to your computer and use it in GitHub Desktop.
XKit.extensions.my_extension = new Object({
variable: 0,
do_something: function () {/* etc */},
//have to do this with e.g. $(selector).each() because we need the "this" keyword
this_should_work: function () {
something_happens.then(inner_function);
},
inner_function: function() {
const {my_extension} = XKit.extensions;
my_extension.variable = 5;
my_extension.do_something();
},
this_should_also_work: function () {
something_happens.then(inner_function_two.bind(this));
},
inner_function_two: function() {
this.variable = 5;
this.do_something();
},
//good for short things
this_should_work_as_well: function () {
something_happens.then(() => {
this.variable = 5;
this.do_something();
});
},
});
/* OLD VERSION BELOW OOPS */
XKit.extensions.my_extension = new Object({
variable: 0,
do_something: function () {/* etc */},
//have to do this with e.g. $(selector).each() because we need the "this" keyword
this_should_work: function () {
something_happens.then(inner_function());
},
inner_function: function() {
const {my_extension} = XKit.extensions;
my_extension.variable = 5;
my_extension.do_something();
},
this_should_also_work: function () {
something_happens.then(inner_function_two().bind(this));
},
inner_function_two: function() {
this.variable = 5;
this.do_something();
},
//good for short things
this_should_work_as_well: function () {
something_happens.then(() => {
this.variable = 5;
this.do_something();
});
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment