Javascript method declaration -
is right declare method this?
window['test']['myfunction?'] = function(param) { for(var in([ param.getelementsbytagname('ol'), param.getelementsbytagname('ul') ]){ found += a.length(); } return != 0 ? true : false; }
i use declare method this
var test = function(param){ ... }
but saw first declaration in code. not able that. what's difference in these 2 type of declaration. 1 more efficient?
in javascript, virtually object meaning has set of properties. can access or set these properties in few ways, 2 of relevant here.
the first option window.foo = 'bar';
. way write window['foo'] = 'bar';
first 1 called dot notation, second 1 called bracket notation. bracket notation has 1 advantage on dot notation, type of characters can use. example window.invalid-foo = 'bar'
not work. window['invalid-foo']
on other hand does.
now question; there possibility when encountering window['test']['myfunction?']
original author of code has own framework checks global window.test
object functions. , iterates through these functions , calls them way of testing code.
i not recommend doing things way because:
- you're polluting global namespace.
- you're creating unnecessary confusion using non-standard approach declaring variables.
is 1 way of declaring functions faster other? latter faster enormous amount. we're talking 2 million operations per second versus 1.5 billion operations per second.
Comments
Post a Comment