Jump to content

HOLY ROBIN, BATMAN!


L8V2L

Recommended Posts

First, replacing this:

Object.prototype.toString.call(o).slice(8,-1);
with this:
with(Object){with(prototype){with(toString){with(call([])){slice(8,-1);}}}}
does nothing except add confusion. The second piece of code is far more confusing than the first. With this:
with(object){with(obj){console.log(foo+"n"+foo+"n"+foo+"n"+foo+"n"+prop0+"n"+prop1+"n"+prop2+"n"+prop3);}}
What if both object and obj have a property called foo? Which one are you accessing? At first glance it is ambiguous. Code should not be ambiguous.

Instead of lashing at me, you could inform me(in knowledge me) of ALL the pitfall of the with statement.

You should inform yourself, through research. Any discussion of with should include a statement about the problems with it. Look at this:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/withThere is a giant red box on top pointing out that there are problems, and telling you where to find more information. So read that, don't count on me to explain every possible pro and con with anything you put here. Do your own research.

Since it'll be confined in a function scope, want that make it be more efficient?

It is less efficient than referencing things directly, and less efficient because Javascript will need to traverse the entire scope chain looking for some place it is defined. So, no, it is never more efficient.
Link to comment
Share on other sites

First, replacing this:

Object.prototype.toString.call(o).slice(8,-1);
with this:
with(Object){with(prototype){with(toString){with(call([])){slice(8,-1);}}}}
does nothing except add confusion. The second piece of code is far more confusing than the first. With this:
with(object){with(obj){console.log(foo+"n"+foo+"n"+foo+"n"+foo+"n"+prop0+"n"+prop1+"n"+prop2+"n"+prop3);}}
What if both object and obj have a property called foo? Which one are you accessing? At first glance it is ambiguous. Code should not be ambiguous.
Good point, I did the testing and it came down to the order of which with statement was nested:
with(foo){    with(bar){/*foo bar baz*/    }}
foo will have presence over the access of the property to reference to it's first, before bar.Here's the actually test:
//input == I.P.:>var object = {}, obj = {prop0:0,prop1:1, prop2:2, prop3:3, foo:"hi"};    counter = -1;object.__defineGetter__('foo', function() {	return ++counter;});with(obj){with(object){console.log(foo+"n"+foo+"n"+foo+"n"+foo+"n"+prop0+"n"+prop1+"n"+prop2+"n"+prop3);}} //output == O.P.:01230123undefined> var object = {}, obj = {prop0:0,prop1:1, prop2:2, prop3:3, foo:"hi"};    counter = -1;object.__defineGetter__('foo', function() {	return ++counter;});//input == I.P.:with(object){with(obj){console.log(foo+"n"+foo+"n"+foo+"n"+foo+"n"+prop0+"n"+prop1+"n"+prop2+"n"+prop3);}} //output === O.P.:hihihihi0123undefined
Link to comment
Share on other sites

You should inform yourself, through research. Any discussion of with should include a statement about the problems with it. Look at this:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with

I read that, I do inform myself, I do my research but I still ask for clarity sake, and understanding.And all they really say is be careful, and to make sure it understandable what's going on. You could simply add an comment explaining what argument in the with statement refer to. I like it(not saying I'll use it in production code.) I like it cause it's part of JavaScript and have an interested behavior of expanding the scope chain environment.
Link to comment
Share on other sites

You could simply add an comment explaining what argument in the with statement refer to.

You could, yeah, but the best code is simple enough that it does not require comments. Writing object.foo is obvious, you don't need to write a comment saying that you are accessing object.foo. It's right there in the code, there's no confusion.
Link to comment
Share on other sites

Do anyone know any good xml books out there. I search, and came up with nothing but bad comments on the book. And it seem to be that there is no recent printing of the topic.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...