2016-07-20 4 views
0

私はjavascript/jqueryを書くためにVisual Studioを使用しています。例は、私が入力します。javascript/jqueryの宣言とオーバーライド

$('#selector').text('foo') 

その後、私はtext押しF12を選択します。 VSは私にファイルjquery-2.2.3.intellisense.jsを示し、自動的fucntionにまでスクロールします:

'text': function() { 
    /// <signature> 
    /// <summary>Set the content of each element in the set of matched elements to the specified text.</summary> 
    /// <param name="textString" type="String">A string of text to set as the content of each matched element.</param> 
    /// <returns type="jQuery" /> 
    /// </signature> 
    /// <signature> 
    /// <summary>Set the content of each element in the set of matched elements to the specified text.</summary> 
    /// <param name="function(index, text)" type="Function">A function returning the text content to set. Receives the index position of the element in the set and the old text value as arguments.</param> 
    /// <returns type="jQuery" /> 
    /// </signature> 
    } 

私はそれが唯一の機能の説明が含まれていることを知っています。私もそれをしたい。

ある場所にある説明で関数を宣言し、それを別の場所でオーバーライド(実装)します。

// first 
var Add = function (a, b) { 
    /// <signature> 
    /// <sumary>Add 2 numbers</sumary> 
    /// <returns type="Number" /> 
    /// </signature> 
}; 

// second 
@override 
@** 
* Add 2 numbers 
* @param {Number} a: Number a 
* @param {Number} b: Number b 
* @return {Number} 
*/ 
var Add = function (a, b) { 
    return a + b 
}; 

さて、私が入力したとき:このよう

var sum = Add(2, 3); 

私はAddを選択し、F12を押すと、私はVSはthe first機能(ない秒)に当たると考えたいです。

私の質問:どうしたらいいですか?

私は、ファイル another.jsintellisense.annotate(jQuery, {});

intellisense.annotate(jQuery, { 
    'Add': function() { 
     /// <signature> 
     /// <summary>Add 2 numbers</summary> 
     /// <param name="a" type="Number">Number a</param> 
     /// <param name="b" type="Number">Number b</param> 
     /// <returns type="Number" /> 
     /// </signature> 
    } 
}); 

にファイルjquery-2.2.3.intellisense.jsと機能をオープンしようとしました

+0

これだけではできません。 – underscore

+0

'visual-studio'であなたの質問にタグを付けるべきです。タグを適切に使用すると、他の人があなたに返答するのに役立ちます。 – cezar

答えて

0

$.fn.extend({ 
    /** 
     * Add 2 numbers 
     * param {Number} a: Number a 
     * param {Number} a: Number b 
     * return {Number} 
    */ 
    Add: function (a, b) { 
     return a + b 
    } 
}); 

テスト:

$('#selector').Add(2, 3) 

選択AddとプレスF12 VSは関数intellisenseを正しく指します(関数Addの実装はこの場合意味しませんが)。)

関連する問題