簡體   English   中英

在控制台中調用原型方法時,Chrome Web檢查器顯示異常符號

[英]Chrome Web inspector shows unusual symbol when calling prototype method in console

因此,我有一個名為“ createGameObjectConstructor”的函數,該函數帶有一個函數,原型向該函數添加原型和方法,然后返回該函數。可以像這樣使用

Monster = createGameObjectConstructor(function () {
    this.evilness = 9001;

}, {
    eatHuman:function () {
        console.log('human consumed');
    }, type:'scary'
});

和“ createGameObjectConstructor”看起來像這樣

createGameObjectConstructor = (function () {

    var recent = function () { //every actual object constructor will share this method
        return (instance.length> 0) ? instance[instance.length - 1] :null;
    };


    return function (constructor, prototype) { //createGameObjectConstructor

        var instanceArray = new Array();

        constructor.prototype = prototype;

        return function (){ //actual object's constructor
            var instance = new constructor();
            instance.constructor = constructor;
            instanceArray.push();
            return instance;
        };

        f.recent = recent;

        return f;

    }

}());

但是當我打電話給Monster().eatHuman(); 在Chrome的控制台中,它返回的函數未定義,但旁邊帶有一個怪異的箭頭,這是因為我奇怪的編碼在某種程度上導致了它對代碼的評價嗎?

箭頭

這是一個小提琴http://jsfiddle.net/UZmL9/

這只是意味着函數的返回值undefined

如果未找到顯式的return語句,則所有JavaScript函數默認都返回undefined

function foo(){
    console.log("Hi");
}
foo(); // you will get the same 'undefined'

function foo(){
    console.log("Hi");
    return 5;
}
foo(); // you will get 5 with that arrow

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM