Comments (3)
JavaScript does not have block scope so there is no such thing as a conditionally defined variable. This is a pretty big gotcha in the language, and why it is best practice to define all variables at the top of a function. Strophe violates this principle with impunity (which, is quite bizarre considering the JSLint configuration at the top of the core source file).
from strophejs.
@discordinoffice That's actually wrong. JavaScript hoists variable declarations to the top of the scope and assigns the variable where it was declared. This is the case for everything except for the catch
and let
block, where it creates a block scope.
Read up: https://developer.mozilla.org/en/JavaScript/Reference/Scope_Cheatsheet#Hoisting
This means that this:
function hoistMe() {
hoisted = "I'm a hoisted variable";
alert(hoisted);
var hoisted;
}
is evaluated as:
function hoistMe() {
var hoisted; // hoisted to the top of the current scope
hoisted = "I'm a hoisted variable";
alert(hoisted);
}
from strophejs.
Thank you for that correction; it is much appreciated! That is pretty esoteric, and is definitely something to be aware of.
from strophejs.
Related Issues (20)
- Strophe only send message out when new message comes in HOT 1
- How to register a new account on server with strophejs? HOT 1
- login with anonymous users getting not-authorised message HOT 4
- connection problem with multiple tabs HOT 1
- Sending message
- Update sha1.js to 2.2 HOT 1
- Update md5.js to 2.2 HOT 1
- getResponse handles errors inconsistently
- Digest MD5 fails due to error in Base64.js
- Finding Problem with get the session
- Port to Dart
- How to solve CROSS exception HOT 3
- Possible bug in escaping/unescaping text HOT 1
- addHandler issue on message HOT 2
- not getting message in ideal possession long time
- java.util.concurrent.ThreadPoolExecutor
- if ios, connecting, document cannot click,scroll... ,andriod and PC not found this question.
- "XHR open failed.
- "XHR open failed." in BOSH in IE9 with v1.2.8
- How to get MUC-Light room chat history
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from strophejs.