Prev: initializing style sheets and javascript
Next: FAQ Topic - How do I find the size of the window? (2010-04-19)
From: Johannes Baagoe on 20 Apr 2010 00:58 nick : > But hey, I worked out the weirdness with toString vs. valueOf... going > to post about it in response to my first post so it doesn't get lost. As the second programmer told the first who asked "What does '\u0007' mean?", I'm not sure, but it may ring a bell. I vaguely recall having encountered that problem, but I don't remember if it was ever solved, or how. Your explanation will be welcome. Sorry about not having responded earlier, by the way, I was concentrating on other matters. -- Johannes
From: Dr J R Stockton on 19 Apr 2010 12:26 In comp.lang.javascript message <daa5afc9-f5d5-47ab-a4b2-3d68139f1029(a)8g 2000yqz.googlegroups.com>, Sun, 18 Apr 2010 12:52:49, nick <nick___(a)fastmail.fm> posted: >I decided to I wanted to subclass the native Date object, but realized >that you can't call Date.prototype's function properties with anything >but a 'pure' date object as the execution context. So, I decided to >wrap all of Date.prototype's important functions, which worked out >pretty well... You might like to look at : <URL:http://www.merlyn.demon.co.uk/js-dobj2.htm> Alt. date object <URL:http://www.merlyn.demon.co.uk/js-datex.htm> Date errors <URL:http://www.merlyn.demon.co.uk/js-dates.htm> Date index, ff. Note that, when reporting unexpected results, it is well to indicate which version of which browser (or other host) is in use, ditto for operating system, and the location to which your system is set. -- (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05. Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
From: nick on 19 Apr 2010 16:46 On Apr 19, 12:26 pm, Dr J R Stockton <reply1...(a)merlyn.demon.co.uk> wrote: > > You might like to look at : > <URL:http://www.merlyn.demon.co.uk/js-dobj2.htm> Alt. date object > <URL:http://www.merlyn.demon.co.uk/js-datex.htm> Date errors > <URL:http://www.merlyn.demon.co.uk/js-dates.htm> Date index, ff. Nice... the thing I'm working on is a port of PHP's date() formatting; looks like you've done something pretty similar. I'll post what I've got in pastebin or something when I get home so you can have a look, it might be interesting to you. > Note that, when reporting unexpected results, it is well to indicate > which version of which browser (or other host) is in use, ditto for > operating system, and the location to which your system is set. Good point. I believe I tested it in latest versions of GC and FF, but I was on my way out the door when I got to that point so I may be mistaken. The behavior I was noticing was basically: (''+new Date) == (new Date).toString() (''+new Date) != (new Date).valueOf() (''+new MyDate) != (new MyDate).toString() (''+new MyDate) == (new MyDate).valueOf() This isn't what I expected (I expected ''+anything to be the same as anything.toString() pretty much across the board), but it's probably a result of my not having taken the time to fully understand the inner workings of toString and valueOf. I'll try to post something as little more coherent (and respond to Asen, sorry Asen) when I get back to the house ;) -- Nick
From: nick on 19 Apr 2010 23:52 On Apr 18, 5:30 pm, Asen Bozhilov <asen.bozhi...(a)gmail.com> wrote: .... > That design is not really good decision. It is memory inefficient and > break forward compatible with non generics methods for Date > instances. True, but can you think of a more efficient way to to extend Date? Or do you think I should scrap the idea of extending Date altogether and instead make other classes / functions that act on instances of Date? > By specification that is normal behavior, because Date instances have > special [[DefaultValue]]. During evaluation of addition expression, > objects will be converted to primitive value. For type converting will > be use internal [[DefaultValue]] of that object, without passing hint > argument. Thanks for the explanation. Apparently only pure Date instances get this special behavior, just being an 'instanceof Date' isn't good enough. I guess DefaultValue and hint are internal stuff I have no control over? [snip] > For object referred by `obj' if call [[DefaultValue]] method with no > hint, will be treat as hint is Number. How can I call it with a hint... by doing something like Number(myDate) or String(myDate)? -- Nick
From: Asen Bozhilov on 22 Apr 2010 16:40 nick wrote: > Asen Bozhilov wrote: > > By specification that is normal behavior, because Date instances have > > special [[DefaultValue]]. During evaluation of addition expression, > > objects will be converted to primitive value. For type converting will > > be use internal [[DefaultValue]] of that object, without passing hint > > argument. > > Thanks for the explanation. Apparently only pure Date instances get > this special behavior, just being an 'instanceof Date' isn't good > enough. > I guess DefaultValue and hint are internal stuff I have no control > over? Internal methods are not inherited via prototype chain. For example Function instance has internal [[Call]] and [[Construct]] which are used during evaluation of `CallExpression` and `NewExpression`. If I inherit from Function object, created object after that does not have these internal methods because they are not inherited via prototype chain. For example of my words: function ExtendFunction() {} ExtendFunction.prototype = function(){}; var f = new ExtendFunction(); print(f instanceof Function); //true /* If object has [[Call]] method typeof * must return primitive string value "function" */ print(typeof f == 'function'); //false try { f(); //Invoke internal [[Call]] }catch (e) { print(e instanceof TypeError); //true } try { new f(); //Invoke internal [[Construct]] }catch (e) { print(e instanceof TypeError); //true } > > For object referred by `obj' if call [[DefaultValue]] method with no > > hint, will be treat as hint is Number. > > How can I call it with a hint... by doing something like > Number(myDate) or String(myDate)? The question is to which value you want to convert that object? When you answer on that question you can find way to do that conversion. See: <URL: http://www.jibbering.com/faq/faq_notes/type_convert.html /> By Richard Cornford.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: initializing style sheets and javascript Next: FAQ Topic - How do I find the size of the window? (2010-04-19) |