如何调用函数内的函数?

Ben*_*Ben 3 javascript

如何调用此函数内部的函数?

var video = function() {

    this.name = "Name of Video";
    this.desc = "Short Description of Video";
    this.long = "Long Description of Video";

    function metadata(){
        return {
            name : this.name,
            shortDescription : this.desc,
            longDescription : this.long
        };
    };

};
Run Code Online (Sandbox Code Playgroud)

Igo*_*gor 8

使它成为新对象的方法:

var video = function() {

    this.name = "Name of Video";
    this.desc = "Short Description of Video";
    this.long = "Long Description of Video";

    this.metadata = function(){
        return {
            name : this.name,
            shortDescription : this.desc,
            longDescription : this.long
        };
    };
};

var videoObject = new video();
videoObject.metadata();
Run Code Online (Sandbox Code Playgroud)


use*_*654 5

除了所述功能之外,你不能.

var video = function() {

    this.name = "Name of Video";
    this.desc = "Short Description of Video";
    this.long = "Long Description of Video";

    function metadata(){
        return {
            name : this.name,
            shortDescription : this.desc,
            longDescription : this.long
        };
    };
    metadata();

};
Run Code Online (Sandbox Code Playgroud)