Null [object Object]
-
Continuing the discussion from History of Avatar History (complete with @accalia's swappable heads):
Something went weird then @abarker edited his post:
-
-
SSTPFY
-
whey did i get an @mention for that post?
-
whey did i get an @mention for that post?
Maybe from the inadvertent @mention in the link?
@RaceProUK said:Continuing the discussion from History of Avatar History (complete with @accalia's swappable heads):
-
And I just realized we screenshotted two different bugs:
null [Object object]
as number of replies originally, and anothernull [Object object]
as the text of the linked topic in my screenshot.Pointing this out for anyone else as blind as me.
-
...seriously blind
NOT_A_BUG THREAD_TITLE
-
Desk. Head. Sleep required.
-
!LikeBot r null [object Object]
-
Remembered 'null' as "[object Object]".
-
[object Object]
is what Javascript thinks is a sensible way to convert an object into a string.
-
null is null or not an object.
-
-
Unless you're in database land, where null is not equal to any object, but it's also not not equal to any object either. Nor is it even equal to itself. It simply is.
[code]
select object from (select 1 as object) where null <> object0 rows
select object from (select 1 as object) where null = object
0 rows
select object from (select 1 as object) where null = null
0 rows
select object from (select 1 as object) where null is null
1 row [1]
[/code]
-
typeof null === 'object'
-
had to clarify myself with a mega-edit. my initial flippant remark was too far off base to leave standing.
-
function realTypeOf(obj) { return Object.prototype.toString.call(obj).slice(8, -1); };
Filed under: Javascript is amazing!
-
Nope, that doesn't work either.
Object.prototype.toString.call(new function Potato(){}).slice(8, -1); -> Object
-
Uhhh, I don't know what to tell you (other than 'you done fucked it up'...):
C:\>node > function realTypeOf(obj) { ... return Object.prototype.toString.call(obj).slice(8, -1); ... }; undefined > realTypeOf(function() {}) 'Function' >
-
a new function is an object.
[code]
Object.prototype.toString.call(function Potato(){}).slice(8, -1);"Function"[/code]
-
Ooh, my assertion holds
:D
-
the difference between what you two did, put in longer form is this:
[code]
var a = function Potato(){};
Object.prototype.toString.call(a).slice(8, -1);"Function"
Object.prototype.toString.call(new a).slice(8, -1);
"Object"
Object.prototype.toString.call(null).slice(8, -1);
"Null"
[/code]
Filed Under: How the fuck do you add blank lines in a code block....
-
Use a different code block delimiter, that's how. Note that four spaces is the only way to talk about triple backticks. ```
-
Note that four spaces is the only way to talk about triple backticks.
Fail. The first rule of triple backticks is, "Don't talk about triple backticks."
-
(<code> inside <pre>) orlike this
like this
Just not like this:
[code]
Here'syour
problem
[/code]
-
or i could have done
here is some code
here is some code
or
here is some code
here is some code
to get a code-color background on the blank line.
but i did not want to do such retarded shit.
i just wanted a fucking [code] block that prints what it has in it.
-
Also, interesting that <pre> in a <code> kills the background color
and that blakeyrat's law continues to hold - even topics about a dicsourse bug degenerate into complaints about other dicsourse annoyances.
-
retarded shit
A mixture of at least three different formatting systems, all of which have slightly different appearances.
int main()
[code]{[/code]
printf("Today I learned how to truly hate.\n")
</preprintf("Now I am at peace.\n")
[code] worst[worst]++;[/code]
return DO_NOT_LOOK_AT_THE_RAW;
}
-
int main() {
return "I think I'll just look at the page source for reference "
"and build my HTML directly in the future" + 1;
}
-
Except that calling the new operator on a function value constructs a new instance of that type.
String
is a function,new String
is a String object.
-
This post is deleted!
-
Also, interesting that <pre> in a <code> kills the background color
That was bugging me— AFAICT, it's omitting the > from a </pre> tag which causes the next set of <code><pre> to be messed up with no background colour...
no background
no background
no background
no background
Half-formed tags are their own special kind of formatting in Discourse...
EDIT: and of course, never trust the preview window either...
-
Except that calling the new operator on a function value constructs a new instance of that type. String is a function, new String is a String object.
Which is exactly what I just said? the
new a;
in my code yields the same result as thenew function Potato(){}
in your code...[code]
new function Potato(){};Potato {}[/code]
[code]
var b = new function Potato(){};b;
Potato {}[/code]
[code]
var a = function Potato(){};new a;
Potato {}[/code]
[code]
var a = function Potato(){};var b = new a();b;
Potato {}[/code]
-
var a = function Potato(){};
Object.prototype.toString.call(a).slice(8, -1);
>"Function"
Object.prototype.toString.call(new a).slice(8, -1);
>"Object"
?
-
I fail to get what you are getting at...
unless you're struggling with my not having redeclaredvar a = function Potato(){};
since it carries over in the chrome console i'm testing in.basically,
new function Potato(){};
yields the same result as
var a = function Potato(){};new a;
--scratch that last one.. wrong pastaThey all make a Potato object.
-
They all make a Potato object.
Yes, and as I said in the post that started this conversation:
Nope, that doesn't work either.
Object.prototype.toString.call(new function Potato(){}).slice(8, -1); -> Object ```</blockquote> The code @tar wrote returns "Object" when it should return "Potato".
-
The code @tar wrote returns "Object" when it should return "Potato".
No, that's the code you wrote, which is wrong and broken as @darkmatter explained.
-
Because there's no such thing as a Potato type? There is a Potato Object, which it correctly identifies as an Object, because it is.
-
Why can I have [object Number] or [object String] but not [object Potato]?
-
Because the point of his code is to print whether something is an Object, Function, Null, etc.... not a Potato or a Witch or a Deskjockey
[code]Object.prototype.toString.call(null).slice(8, -1);"Null"[/code]
[code]
Object.prototype.toString.call(function(){}).slice(8, -1);
"Function"[/code]
[code]Object.prototype.toString.call(new function(){}).slice(8, -1);
"Object"[/code]
-
Object.prototype.toString.call(new String()).slice(8, -1);
"String"
Object.prototype.toString.call(new Number()).slice(8, -1);
"Number"
Object.prototype.toString.call(new Function()).slice(8, -1);
"Function"
Object.prototype.toString.call(new Image()).slice(8, -1);
"HTMLImageElement"
Object.prototype.toString.call(new null()).slice(8, -1);
Uncaught TypeError: object is not a function
-
> new null() TypeError: object is not a function at repl:1:2 at REPLServer.self.eval (repl.js:110:21) at Interface.<anonymous> (repl.js:239:12) at Interface.emit (events.js:95:17) at Interface._onLine (readline.js:203:10) at Interface._line (readline.js:532:8) at Interface._ttyWrite (readline.js:761:14) at ReadStream.onkeypress (readline.js:100:10) at ReadStream.emit (events.js:98:17) at emitKey (readline.js:1096:12) >
-
So
Object.prototype.toString.call(null).slice(8, -1);
should returnObject
, then, since null is object.
-
Yeah, I don't get what your point is. It's taking the [object Number] or [object String] that you get back from the plain call to the "toString" method in the prototype and pulling off the end piece of that coerced to string to return as the "Type". That method doesn't extend the functionality in any fashion to return the other non-native types natively.
[code]
var a = function Potato(){};a.prototype = { };
a.prototypeObject { }[/code]
[code]
String.prototype
String {fmt: function, w: function, loc: function, camelize: function, decamelize: function…}
[/code]
-
Note: Starting in JavaScript 1.8.5 toString() called on null returns [object Null], and undefined returns [object Undefined]
-
you can override the toString on an object to get your type back....
[code]
function Potato(){};Potato.prototype.toString = function(){ return "[object Potato]"; }
(new Potato).toString();"[object Potato]"
[/code]
but it won't help the base object's toString() call to recognize it...
[code]
Object.prototype.toString.call(new Potato);
"[object Object]"
[/code]
[code]
Potato.prototype.toString.call(new Potato());
"[object Potato]"
[/code]
also, since i hardwired the Potato object's toString:
[code]Potato.prototype.toString.call(null);
"[object Potato]"[/code]I suppose that if you expected your new Object type to be returned natively, it would be broken?
to be fair,
[code]Potato.prototypePotato {toString: function}[/code]
so you'd think that "Potato" could be obtained!
-
I don't expect that this is going to help at all, but here's where that
realTypeOf()
function came from, and the rationale behind it...http://bonsaiden.github.io/JavaScript-Garden/#types.typeof
The
typeof
operator... is probably the biggest design flaw of JavaScript, as it is almost completely broken.
-
I think that is why I didn't see what @ben_lubar was getting at... because I thought it was just replacing "typeof" for more object native cases - returning the XXXX from when you get "[object XXXX]" as output from toString() - instead of always returning "object" for all objects, not that it was somehow trying to allow custom object type definitions.
Technically you COULD add custom object type definitions by modifying the toString in the prototype of the base Object... but that's probably not the greatest plan.
-
Technically you COULD add custom object type definitions by modifying the toString in the prototype of the base Object... but that's probably not the greatest plan.
[code]
//i just want my motherfucking potatoes.
Object.prototype.toString = function(){ return "[object Potato]"; }; Object.prototype.toString.call(new Potato).slice(8,-1);"Potato"
[/code]
-
Annnnnnd more null bugs, dicsourse shat bricks on itself after I posted:
Had to hard refresh F5 to get it to let me post again.