jquery - How to call a function of the caller's namespace with this? -
goal: i'm trying shorten how call function of same namespace in function using "this" instead of namespace string. apparently "this" wouldn't work function, works variable. wish know if it's due misusage, or call function namespace string way.
another beginner's question: i'm calling function of same namespace caller's. googled , said calling: this.myfunction work, doesn't. ideas? thanks.
i'm calling: singleentry.editcontent.accept(tinymce.get('editcontentta').getcontent());
from: index.fragment.singleentry.editcontent.load
i've tried as: this.accept, firebug says this.accept not function...
index.fragment.singleentry.editcontent.load = (function(singleentry) { return function() { // prepare edit dialog $("#editcontentdiv").dialog({ autoopen : false, height : 500, width : 600, modal : true, buttons : { "ok" : function() { singleentry.editcontent.accept(tinymce.get('editcontentta').getcontent()); $(this).dialog("close"); }, "cancel" : function() { $(this).dialog("close"); } }, open : function() { // set value edit area tinymce.get("editcontentta").setcontent($("#vecontent").html()); } });
i'm not quite following ultimate goal, theory in hopes helps there:
when call function via object's property (so, via dotted notation, or []
notation), this
within function call object reference. when call
singleentry.editcontent.accept(tinymce.get('editcontentta').getcontent());
...within call, this
refer singleentry.editcontent
.
if want this
refer else, can use call
:
singleentry.editcontent.accept.call(thisobj, tinymce.get('editcontentta').getcontent()); // ^^^^^^^^^^^^^
...where thisobj
whatever object want function see this
during call. more here: mythical methods
call
property of (real) javascript functions, , provide make easy call function , set this
should (what context is) during call. there's apply
, same thing accepts arguments pass function array rather discrete arguments. e.g., these 2 calls identical:
// using `call` singleentry.editcontent.accept.call(thisobj, tinymce.get('editcontentta').getcontent()); // using `apply` singleentry.editcontent.accept.call(thisobj, [tinymce.get('editcontentta').getcontent()]); // note `[]` -----^
all of made possible because in javascript, this
determined entirely how function called, not where it's defined — think know that, based on question, worth flagging anyway.
Comments
Post a Comment