This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 229979

Summary: Properties declared using self not found
Product: javascript Reporter: Vladimir Riha <vriha>
Component: EditorAssignee: Petr Pisl <ppisl>
Status: REOPENED ---    
Severity: normal CC: mfukala, phejl, pjiricka
Priority: P4    
Version: 7.4   
Hardware: PC   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description Vladimir Riha 2013-05-20 08:46:58 UTC
To reproduce, please try to create KnockoutJS sample project (KnockoutJS must-play game list) and open the html page

=> Navigator does not contain gamesToPlay, gamesCount etc. and also code completion in 

 <strong data-bind="text: |"></strong>

does not offer these properties. It is because they are declared using self pattern


self = this;
self.gamesToPlay = ko.observableArray(games);




Product Version: NetBeans IDE Dev (Build web-main-10560-on-20130519)
Java: 1.7.0_21; Java HotSpot(TM) Client VM 23.21-b01
Runtime: Java(TM) SE Runtime Environment 1.7.0_21-b11
System: Linux version 3.2.0-43-generic-pae running on i386; UTF-8; en_US (nb)
Comment 1 Marek Fukala 2013-05-20 13:39:31 UTC
Petr Pisl already implemented #229717 - The common constructor pattern with "self" is not supported. So possibly sg. needs to be also done at the KO side or there's a bug in the ppisl's change.
Comment 2 Petr Hejl 2013-05-21 07:12:58 UTC
Yep pretty strange. I guess some more tweaking has to be done for self pattern in the model. I'll try to (at least) evaluate it.
Comment 3 Petr Hejl 2013-05-21 08:01:28 UTC
It looks like the self variable in your sample is global and that's why the self-pattern detection does not work imo. Is the use of global variable intentional?
Comment 4 Vladimir Riha 2013-05-21 08:04:31 UTC
I think that is just unfortunate choice of sample's author
Comment 5 Petr Hejl 2013-05-21 08:08:32 UTC
Petre, can you tweak the self pattern solution?
Comment 6 Roman Svitanic 2015-03-02 15:17:35 UTC
Issue is not reproducible using current dev build (and using KO sample project):
Product Version: NetBeans IDE Dev (Build 20150302-84205dde7ed0)
Java: 1.7.0_75; Java HotSpot(TM) 64-Bit Server VM 24.75-b04
Runtime: Java(TM) SE Runtime Environment 1.7.0_75-b13
System: Mac OS X version 10.10.2 running on x86_64; UTF-8; en_US (nb)
Comment 7 Vladimir Riha 2015-03-02 15:25:01 UTC
This is still reproducible (albeit it is a bad pattern), you need to make self on line 10 global again:

self = this


The sample project author fixed it after I asked him to do so [1] so it would work in NetBeans :)


[1] https://github.com/bernardobrezende/KnockoutJS.Tips/issues/1
Comment 8 Roman Svitanic 2015-03-18 16:18:20 UTC
(In reply to Vladimir Riha from comment #7)
> This is still reproducible (albeit it is a bad pattern), you need to make
> self on line 10 global again:
> 
> self = this

Thanks for the clarification,. This can be reproduced in Plain JS as well:

MyModel = function() {
    self = this;
    self.demoProperty = 'demo';
};
var m = new MyModel();
m.|

demoProperty is not offered by CC.
I am lowering to P4, since it is really bad practice.