|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On March 16 2013 12:33 tec27 wrote:if you're actually checking if a variable equals or does not equal a falsy value, you are generally not doing the right thing anyway Ah, that clears things up quite a bit. js's non-transitive == always made me feel viscerally uncomfortable. Truthy/falsy helps. Is it possible to just use non-type-converting === everywhere instead (jshint could enforce this I imagine)?
Frontend still makes me
|
Yes, you could, but there are a helluva lot of times where you don't really care if something is, for instance, null or empty string, just that it's not an actual string.
I feel thatif(myStr) { ... } is more readable than
if(myStr !== null && myStr !== '') { ... }
But yes, there are people who advise you to always use ===. Personally I think that's a bit like advising you to not try and understand the language's semantics and just asking for confusion, but to each their own 
The JSHint option for enforcing that is 'eqeqeq', so you can enforce it with the modeline:/*jshint eqeqeq:true */ // code here...
|
^ is === equal to what == is for other languages? If yes, then what is == used for in JS, assuming it exists?
|
|
|
Yeah, the technical term is 'type coercion'. == is equality with type coercion, === is without (This operator is generally present in languages that have automatic type coercion, like JS and PHP). You can read more about how types get coerced here:
http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/
(I'd recommend it over the stuff linked in the stackoverflow response above, its much more straightforward than some of the stuff there and Crockford is too dogmatic for anyone's good)
|
I have a webpage, and I want the links to be opened in a new tab. I used target="_blank" , but apparently it does not validate as XHTML Strict 1.0. Is there a way to make it so (another tag/method), or is it impossible under this doctype?
|
Target is not valid under 'strict' doctypes. If you want to use it you'll need to use a transitional (or, ideally, use HTML5). Is there any particular reason you want to use that doctype in the first place? There are a lot of sites that use it completely incorrectly (like, for instance, they send the page with 'Content-type: text/html' which makes all browsers ignore that doctype), and picking a doctype other than <!DOCTYPE html> at this point is probably a bad move.
See: http://www.hixie.ch/advocacy/xhtml
|
It's a project for uni. One of the requirements is that we have to use the Strict Doctype. Opening links in a new tab is not a requirement, but just a feature I wanted to add.
|
You can't use this in XHTML.
|
Hyrule19174 Posts
On March 17 2013 16:38 GhostLink wrote: It's a project for uni. One of the requirements is that we have to use the Strict Doctype. Opening links in a new tab is not a requirement, but just a feature I wanted to add. JavaScript can help you out there.
|
On March 17 2013 22:54 tofucake wrote:Show nested quote +On March 17 2013 16:38 GhostLink wrote: It's a project for uni. One of the requirements is that we have to use the Strict Doctype. Opening links in a new tab is not a requirement, but just a feature I wanted to add. JavaScript can help you out there.
Just because you avoid that the w3c validator will give you an error, it doesn't mean that the code suddenly gets valid. There is a reason why the target attribute was removed and replacing it with JS certainly doesn't make the code any valid.
|
On March 17 2013 16:38 GhostLink wrote: It's a project for uni. One of the requirements is that we have to use the Strict Doctype. Opening links in a new tab is not a requirement, but just a feature I wanted to add. You should let the user decide if he wants to open a link in a new tab or not - do not force a certain behaviour. Any link that stays within the same site should never be opened in a new tab.
Best you can do is have a different style for links that lead to external sites, and let the use decide.
|
Sites will often use new tab/window for external links and same tab for internal links. I find it a good convention.
|
In C++, what is a getter and setter method? I tried googling but I don't think I manage to find anything that help me understand what the hell are those.
|
On March 18 2013 07:54 MiyaviTeddy wrote: In C++, what is a getter and setter method? I tried googling but I don't think I manage to find anything that help me understand what the hell are those.
Getters and setters are really simple.
Say you have a class:
class Kitten { private string furColor; }
// the getter, which "gets" the fur color of the kitten string getFurColor() { return furColor }
// the setter, which "sets" the fur color of the kitten void setFurColor( String furColor) { this.furColor = furColor; }
Basically: Setters and getters are ways to access private variables.
|
On March 18 2013 07:54 MiyaviTeddy wrote: In C++, what is a getter and setter method? I tried googling but I don't think I manage to find anything that help me understand what the hell are those.
class Whatever { private: int x; public: int getX() { return this->X; } // getter int setX(int newX) { this->X = newX; } // setter }
Getters and setters prevent direct access to the private variables of a class and allow adding validation and triggers. Generally it's always a good idea to use getters and setters instead of making a variable public even if you don't require any validation yet because at some point in the future, you most likely want to add some sort of validation and that way you don't have to change your whole code. Also, there are many cases where you want a variable to be e.g. read-only, so having the habit of using getters and setters you can just not write the setter and that way the variable can't be set from the outside.
|
Thanks alot Abductedonut & Morfildur 
The last few topics I'm still really confused about is: -Inheritance -Virtual functions -Pure virtual -Abstract classes
any examples or primers would be greatly appreciated! and this is helping me towards finishing my assignment.
|
On March 18 2013 09:00 MiyaviTeddy wrote:Thanks alot Abductedonut & Morfildur  The last few topics I'm still really confused about is: -Inheritance -Virtual functions -Pure virtual -Abstract classes any examples or primers would be greatly appreciated! and this is helping me towards finishing my assignment.
Inheritance - see lecture 26.
[link removed]
Edit: It's Java, so if you're looking for language specific code, then this may not be helpful.
|
On March 18 2013 09:00 MiyaviTeddy wrote:Thanks alot Abductedonut & Morfildur  The last few topics I'm still really confused about is: -Inheritance -Virtual functions -Pure virtual -Abstract classes any examples or primers would be greatly appreciated! and this is helping me towards finishing my assignment.
There is ton of stuff about this on the internet, I suggest you first google and read and if you have any specific questions you should ask more specifically. If you don not know what OO means and what getters and setters are and what inheritance means you should really buy books or google. There are tons of tutorials and explanations for these beginner topics.
|
On March 18 2013 09:00 MiyaviTeddy wrote:Thanks alot Abductedonut & Morfildur  The last few topics I'm still really confused about is: -Inheritance -Virtual functions -Pure virtual -Abstract classes any examples or primers would be greatly appreciated! and this is helping me towards finishing my assignment. These are all related to one another quite heavily.
Inheritance lets you stick one object inside of another completely. Here's a slideshow I made talking about inheritance in C. This is almost exactly like what happens in C++, but it's important to know how to do it (and actually do it yourself) in C first, in my opinion. Read the pdf to understand: what inheritance is, and why it's useful.
The pdf also covers virtual functions and how to implement them.
A pure virtual is a function that must be overridden when a class derives from a type. The compiler will complain if you don't. That's all. This is good for enforcing interfaces.
An abstract class is type that is designed to only be used as a base for derivation. Again, a good example (the only good one I know) is for interfaces.
If you're confused on what an interface is: it is just a set of functions to call. If I employ an interface, then other objects can treat me as if I employ this interface. For example say we make an object to resemble a duck. We have an interface for quacking and swimming. Other code portions can call my quack and swim functions upon me, without knowing about the rest of what I am so long as I employ the duck interface.
|
|
|
|
|
|