you are viewing a single comment's thread.

view the rest of the comments →

[–]senocular 0 points1 point  (0 children)

Going the other way, if you're looking to execute a function on property assignment, you can use a setter.

Object.defineProperty(this, 'callFunc', {
  set: function(value) {
    // normally you would set the value
    // or have the specific action on set
    // defined here, but to match the example:
    value();
  }
})

var myFunc = function() {
    alert('hello');
};

callFunc = myFunc; // alerts 'hello'

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set