webdevRefinery Forum: Use Strict - webdevRefinery Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Rate Topic: -----

User is online @Tom 

  • space
  • Group: Members
  • Posts: 704
  • Joined: 24-May 11
  • Locationspace
  • Expertise:Python

Posted 15 May 2012 - 05:55 PM (#1)

Use Strict


description anyone
Would Someone please give me a basic explanation of when
use strict
is helpful or usefull. All of my jshint's always come out with the following (here's my screw ie script)

var screwIE;

screwIE = function() {
  if (navigator.appName === "Microsoft Internet Explorer" ? document.URL.indexOf("http://itom07.com/sorry") === -1 : void 0) {
    return window.location = "http://itom07.com/sorry";
  }
};

screwIE();

(I know its hackish but I was looking into different ways to write it. (besides the point)

Output:
Line 4: if (navigator.appName === "Microsoft Internet Explorer" ? document.URL.indexOf("http://itom07.com/sorry") === -1 : void 0) {
Missing "use strict" statement.

ocelotapps.com
jr wdR comedian under ThatRailsGuy

View Postarronhunt, on 30 June 2012 - 10:09 PM, said:

Sir you are the first person to make me piss myself laughing. Kudos.
0


User is offline Daniel15 

  • dan.cx
  • Group: Moderators
  • Posts: 3415
  • Joined: 17-April 10
  • LocationMelbourne, Australia
  • Expertise:HTML,CSS,PHP,Java,Javascript,Node.js,SQL

Posted 15 May 2012 - 07:44 PM (#2)

It enables strict mode, which disables some of the "bad parts" of JavaScript. John Resig wrote about it a while ago, and the Mozilla Developer Network has an article on it too.

If you do use it, make sure you test your JavaScript in a browser that supports strict mode (like Firefox 4+ or Chrome).
Daniel15! :D
Posted Image

Repeat after me: jQuery is not JavaScript. It is not the answer to every JavaScript-related question. When you have to write some JavaScript, do not instantly react with "Oh, I'll do that with jQuery!"

Spoiler
0


User is offline arronhunt 

  • I'm a httpster
  • Group: Moderators
  • Posts: 3398
  • Joined: 09-March 10
  • LocationLos Angeles, CA
  • Expertise:HTML,CSS,Javascript,Graphics,Flash

Posted 15 May 2012 - 09:20 PM (#3)

You are putting a ternary operator inside an
if()
statement? Woah man. Woah.
DO NOT OPEN THIS

Spoiler
2


User is offline callumacrae 

  • {{ post.author }}
  • Group: Members
  • Posts: 2862
  • Joined: 20-January 11
  • LocationWarwickshire, England
  • Expertise:HTML,CSS,PHP,Javascript,Node.js,SQL

Posted 15 May 2012 - 11:15 PM (#4)

View Postarronhunt, on 15 May 2012 - 09:20 PM, said:

You are putting a ternary operator inside an
if()
statement? Woah man. Woah.

lol

Also, you should never use void.
Front-end developer and writer
Twitter | GitHub | phpBB Contributor and Website Team Member | lynxphp
0


User is online @Tom 

  • space
  • Group: Members
  • Posts: 704
  • Joined: 24-May 11
  • Locationspace
  • Expertise:Python

Posted 15 May 2012 - 11:38 PM (#5)

View Postcallumacrae, on 15 May 2012 - 11:15 PM, said:

lol

Also, you should never use void.

I was playing with Coffeescript, its just how it generated.

# screw Internet Explorer

screwIE = () ->
	window.location = "http://itom07.com/sorry" if document.URL.indexOf("http://itom07.com/sorry") is -1 if navigator.appName is "Microsoft Internet Explorer"

screwIE() 

ocelotapps.com
jr wdR comedian under ThatRailsGuy

View Postarronhunt, on 30 June 2012 - 10:09 PM, said:

Sir you are the first person to make me piss myself laughing. Kudos.
0


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users


Enter your sign in name and password


Sign in options
  Or sign in with these services