MyObj.Func_A ();
MyObj.Func_A.call (YourObj);
// Example 58
var YourObj =
{
Name : "Barney"
};
function Prefix () { alert ("Prefix executed"); }
function MyFunc () { alert ("MyFunc executed - Name = " + this.Name); }
AJS.AddPrefix (this, "MyFunc", Prefix);
MyFunc.call (YourObj);
--------------------------------------
Output:
Prefix executed
MyFunc executed - Name = Barney
// Example 59
function YourFunc () { alert ("YourFunc executed"); }
function MyFunc ()
{
function MyInner ()
{
alert ("MyInner executed");
}
}
AJS.AddPrefix (this, "YourFunc", MyFunc.MyInner);
YourFunc ();
--------------------------------------
Output (in Firefox):
MyInner executed
YourFunc executed
(typeof IntercepteeOwner === 'object')...Must evaluate to true. If not, AJS will throw an exception because the 'typeof' a function object equates to 'function'. Example Sixty (which does not work) illustrates this.
// Example 60
// Throws exception in AJS
// Does not work in AJS_HP
function YourFunc () { alert ("YourFunc executed"); }
function MyFunc ()
{
function MyInner ()
{
alert ("MyInner executed");
}
MyInner ();
}
AJS.AddPrefix (MyFunc, "MyInner", YourFunc);
MyFunc ();
--------------------------------------
Output (using AJS, and assuming exception is caught by the browser):
Error: AJS.AddPrefix - IntercepteeOwner-argument does
not refer to an object. Client-code call point: undefined
--------------------------------------
Output (using AJS_HP):
MyInner executed
// Example 61
function MyFunc () { alert ("MyFunc executed"); }
function GetInner ()
{
function MyInner () { alert ("MyInner executed"); }
return MyInner;
}
AJS.AddPrefix (this, "MyFunc", GetInner ());
MyFunc ();
--------------------------------------
Output:
MyInner executed
MyFunc executed
// Example 62
function Prefix () { alert ("Prefix executed"); }
function GetInner ()
{
function MyInner () { alert ("MyInner executed"); }
return MyInner;
}
var MyObj =
{
Method : function () { alert ("Method executed"); }
};
MyObj["Method"] = GetInner ();
AJS.AddPrefix (MyObj, "Method", Prefix);
MyObj.Method ();
--------------------------------------
Output:
Prefix executed
MyInner executed