javascriptvisual-studio-2013code-assist

function methods and parameters not appearing in "." reference


Update: See self-answer below, which says, this is a visual studio javascript intellisense issue, which requires a "reference path" solution, and provides a specific solution. The original question led off in the wrong direction.

=======original question below===========================

I've built the below to store and retrieve height and width values for different panes in an VS2013 MVC view. PaneDims contains an array (pncnfgar) of pconfig objects. I'd like to use PaneDims as globally available object that I can access the methods and parameter of using "." notation, e.g PaneDims.getconfig. I'd like to use pconfig as an instantiable object that I can fill from PaneDims.getconfig and then also access the parameters of using "." notation, eg. wrk_pconfig.id.

//=========================

var pconfig = function () {
this.id = ""
this.mh = 0
this.mw = 0
this.lh = 0
this.lw = 0
this.dh = 0
this.dw = 0
}
//========================================
var PaneDims = new function () {
this.currPaneConfig = "";
this.pcnfgar = [];
this.getconfig = function (id) {
    for (i = 0; i < this.pcnfgar.length; i++) {
        if (this.pcnfgar[i].id === id) {
            return this.pcnfgar[i];
        }
    }
}
}
//===================================
function TestPaneDims() {
CreatePaneDimsClass()
SetInitialPanelDims()
}
//====================================
function CreatePaneDimsClass() {
//var PaneDims = new PaneDims;
LoadPanelConfigs();
}
//===========================================

I've omitted the details of LoadPanelConfigs because it all works and it's not the problem.

The problem is after I run CreatePaneDimsClass, then in another script file, when I try to invoke PaneDims in SetInitialPanelDims(),

//================================
function SetInitialPanelDims() {

    PaneDims.currPaneConfig = "dh1w1"
    wrkpc = new pconfig
    wrkpc = PaneDims.getconfig(PaneDims.currPaneConfig)

    b = wrkpc.id
    d = wrkpc.mh
    d = wrkpc.mw
}
//===============================

Again, this all works from a processing standpoint.

The issue is that when I'm writing the code the "." values don't appear. e.g. I'm typing

b = wrkpc.

and I would like to see a list of pconfig parameters appear to select from.

So, am I mistaken that this is possible (been eating too much intellisense in C#)? Or is there something missing that I need to do to make what I want happen?

UPDATE: the . referencing works if the SetInitialPanelDims function is in the same script file as the other code, but not if it is in a difference script file.

So, how might I get the . referencing to work if the PaneDims function is invoked in a separate script file?

UPDATE: Tried creating PaneDims with prototype and instantiation; works fine for processing, but does not solve the code writing issue

function pPaneDims() { }
pPaneDims.prototype.pcnfgar = [];
pPaneDims.prototype.currPaneConfig;
pPaneDims.prototype.getconfig = function (id) {
    for (i = 0; i < this.pcnfgar.length; i++) {
        if (this.pcnfgar[i].id === id) {
            return this.pcnfgar[i];
        }
    }
}

Solution

  • This seems to be a visual studio javascript intellisense issue, which requires a "reference path" solution. That is, to add a comment line like this (THREE forward slashes):

    /// <reference path="~/Scripts/020_DRAFT/MyScript.js" />
    

    at the top of the JS files that you want to have intellisense access to the things in MyScript.js.

    The triggering clue was in here.

    Javascript and VS2012 Intellisense

    I did not understand what was meant by " drag one JavaScript file onto another one " but just writing the reference statement worked fine.

    Reminds me of a "using" statement in C#.

    How to reference multiple files for javascript IntelliSense in VS2010

    http://msdn.microsoft.com/en-us/library/bb385682.aspx

    http://gurustop.net/blog/2012/03/03/javascript-js-intellisense-auto_complete-in-visual-studio-11-beta-the-web-_references-js-file/

    This makes this question more or less irrelevant as it was originally worded.