The code below is used to note some methods to run in particular circumstances so they can be called using a simpler syntax.
var callbacks = {alter: SPZ.sequenceEditor.saveAndLoadPuzzle,
copy: SPZ.sequenceEditor.saveAsCopyAndLoadPuzzle,
justSave:SPZ.sequenceEditor.saveAndLoadPuzzle};
But the code keeps returning an empty object. I've checked with console.log that the methods are defined. I've also tried changing the names, invoking an empty object and then adding the properties as eg callbacks.alter, and tried other changes that shouldn't matter.
Why won't this work?
error is on line 238 of puzzle.js
What exactly is the problem? Will the properties be
undefined
or the calls just not work correctly?If the latter, the problem is most likely that when calling the methods,
this
will no longer refer toSPZ.sequenceEditor
, but yourcallbacks
object; to solve this problem, use the helper functionbind()
(as defined by several frameworks) or wrap the calls yourself:The
apply()
is only necessary if the methods take arguments. See details at MDC.