Comments (3)
###enforcing-new.html
I do not think that in this example, the main thrust is to reduce the number of input characters. So you do protection inside the function constructor. Because if someone accidentally calls her without a new one, it can create global variables or fall with an error in strict mode.
###avoiding-implied-typecasting.html
I agree with you that in most cases this will be the construction that you described, but as I understand it, this example suggests that it is necessary to avoid an automatic type cast, as this can lead to errors as the beginners and experienced developers.
p.s. In you example you get error because some is not defined ;)
###for-loops.html
http://jsperf.com/for-loop-dom (this is a very rough test =) )
I think this example is designed for the most part to work with the tree of the document, as the re-conversion of length collections elements rather expensive operation (such as collections are alive). And if no difference I prefer cache variant.
###for-in-loops.html
- Unfortunately it is not(Personally came across this). Some DOM object does not has this property(or work incorrect).
- When you call someObject.hasOwnProperty It will be a look at the whole prototype chain until it reaches Object.prototype, additional time spent.
- It flows from 2. The object has this property can override anyone else.
###function-declarations.html
Well, as you may have noticed not only a function declaration that is determined before the execution of code, so more and overwrites all that already has that name, and even other function declaration (and it is not corrected during the execution of the function). And since they are determined to run the code it is not always and not for everyone obviously, too much is not always a good trick, especially if you are in command. Oh, and lastly, such a function can only be defined in the body of a function or program level, which is pretty much reduces the area of their ads.
###conditionals.html
&& and || are logical operators, but some times you can use them how something like conditional expressions because they return value of operand.
###revelation.html and module.html
var fakeArray, MakeFakeArray = function () {};
MakeFakeArray.prototype = Array.prototype;
fakeArray = new MakeFakeArray();
(fakeArray instanceof Array); //true
({}).toString.call(fakeArray);//"[object Object]"
p.s. Надеюсь я правильно понял твои замечания и сам что-нибудь полезное ответил. =)
Maksim
from javascript-patterns.
###enforcing-new.html
99% of code's errors is sitting behind the monitor, right? :)
###avoiding-implied-typecasting.html
there are no strict mode in my example :P
###for-loops.html
Thanks for your test, I didn't know about this.
###function-declarations.html
If you work in team you can DISCUSS that moments and problems what you describe will disappear.
###revelation.html and module.html
To your example and to all your comments:
I almost agree with all your comments, but all problems what your have described can be avoid if you create standarts to you and your team, if you provide 100% code review for all commits and if you discuss code with your teammates
from javascript-patterns.
I suppose that this is not anti-pattern due $.data and $.fn.data may be used in different cases:
- $.fn.data supports html5 data attributes meanwhile $.data - not
<div id="entryHolder" data-entry-id="1">
...content
</div>
var holder = document.getElementById("entryHolder");
alert($.data(holder, "entryId")); //shows undefined
alert($(holder).data("entryId")); //shows 1
//BUT!
alert($.data(holder, "entryId")); //shows 1
- $.fn.data can be used in chainings, $.data - not
//legal
$(".selector")
.data("test", "val") //returns jQuery object
.slideUp()
//illegal
$.data(elem, "test", "val") //returns value
.slideUp(); //throws exception
- $.fn.data works with jQuery objects, meanwhile $.data works with DOM elements. Therefore if you had DOM element it's better using of $.data .
//bad practice
$(domElem).data("some", "value");
//preffered
$.data(domElem, "some", "value");
NOTE: It doesn't fluent to chainings.
from javascript-patterns.
Related Issues (20)
- Better jQuery Pattern Append HOT 1
- Page doesn't work well on low resolutions HOT 1
- Patterns not consistently used
- Namespace
- Un-responsive design makes content unusable on smaller screens HOT 2
- String concatenation => Better jQuery Pattern Append
- #5
- #1#
- When this conditional expression can be better than anything else?
- Get a maintainer HOT 3
- Count down to zero HOT 1
- can function declaration be named as a pattern? HOT 3
- about self-defining-functions,some issuse not sure
- Define "trickyness" in for-loop pattern HOT 3
- Maintain this repository HOT 14
- New method declaration convention
- Function declarations -- antipattern? HOT 2
- switch pattern indents `case`; breaks its rule #1
- Fixed position nav overlays content HOT 1
- There is no such method in jQuery
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 javascript-patterns.