Javascript's scoping issues are not that different in declaration visually than that of python which is for all intents and purposes one of the most popular programming languages in the world. In fact it is pretty easy to adopt conventions to avoid scoping issues that make it easy to go from one language to another. Here is an example of something you might see a java dev or python dev write in javascript.
Code JavaScript:var object = { aVariable: "", aHiddenVariable: "", init: function() { var self = this; self.aVariable = self.doSomething('idTag'); self.aHiddenVariable = self.doSomething(self, another-'idTag'); }, doSomthing: function(self, id) { id = self.doSomePrivateThing(id); return document.getElementByID(id); }, doSomePrivateThing: function(something) { return "prefixSomeText" + something; }, doAnotherThingMoreCheeky: function(elementID, hiddenNode, normalNode) { var tag = "#" + elementID; $(tag).bind('keyup', function() { if(typeof hiddenNode != "null") { hiddenNode.value = this.value; } normalNode.value = this.value; return; }); } } object.init(); object.doAnotherThingMoreCheeky('idTag', object.aHiddenVariable, object.aVariable);
That isn't too convoluted at all. Defining self as this in the init and passing it arround makes it easy not to get into conflicts inside jquery functions where this is the dom element you are working on.
It doesn't look too, too different than python.
Code Python:class object: __init__(self): self.aVariable = "" self.aHiddenVariable = "" def doSomething(self, something): return self.aMethodCall(something) def doSomethingMoreCheeky(self, somethingA, somethingB): if(self.aVariable != null): aHiddenVariable = somethingA aVariable = somethingB return def aMethodCall(self, something): return //do some logic here
The syntax of C vs python whitespace indentation are different but passing self around (basically catching the instance) isn't that dirty. I think people complaining in the javascript world might just think Java, .NET and PHP simply are 'right' and 'clean' while javascript and python are 'dirty'.
Of course python passes the instance to a method and you need to recieve it. You could easily use "this" or "that" or "lalalacandyland" to assign the instance a name. Javascript's scoping issues are quite different and you could easily just use the native "this" or even use the object name since it is at a global as soon as you assign.
But that is neither here nor there. The fact remains that looking at the two's sources, following established conventions, will not be too far off in regards to scoping issues at first glance. Some people only do self when they need to scope and that is ok too... javascript has implicit fascets but another person coming in behind you might not be a) a js developer and b) get cought up in this.hell
But meh... it doesn't stop you from learning programming. You just don't learn very many design patterns in javascript or ECMAScript which is hopefully the goal of any programmer because it allows you to interact with other developers and make reusable, extensible components.




Reply With Quote

. IMHO C# and C++ are very good starting points as they teach you good solid techniques and overall the basics of how to program. And for the most part C is a strongly-typed language
Bookmarks