Trying to do this

/*Javeline Javascript simple forum API by Makerimages v1.0*/

(function(){

    Javeline={};
    alert("hia");
    Javeline.isNameSpace=true;
    alert("hia");
    Javeline.toString= function() { return "Javeline"; };

    Javeline.Application=Application();
    Javeline.Application.create();
    alert("appmade");

}());

function Application()
{
    function create()
    {
        Javeline.Application=this;
        alert(Javeline.Application);
    }
}

why wont the code not run Javeline.Application.create() ?

also the toString returns everything on that line after the =

有帮助吗?

解决方案

This is probably what you want:

Javeline.Application=new Application();

//....

function Application()
{
    this.create = function()
    {
        Javeline.Application=this;
        alert(Javeline.Application);
    }
}

Just calling Application will return undefined, since the function doesn't have a return statement. Calling it with the new keyword will give you a new object. However, to add the function create as a property to this new object, you have to declare it as a property of this inside of create.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top