Reputation: 257
Problem for example: In general null object
means additional class which handle cases when object not found etc.
In Ruby you can also define method for Nil
class. And I want realise something similiar in js.
That's what gives me hope typeof(null) //=> object
, but in same time null instanceof Object //=> false
. So defining method for Object
gives me nothing.
So the final question: is there any hacks to define method on built-in types?
Upvotes: 0
Views: 87
Reputation: 17757
You can do that in javascript too.
I am not sure whether I understand your question.But here is my take on it.
alert(typeof(null));//gives you object.
MyObject=Object.create(null);
This means
MyObject doesn't inherit from anywhere
MyObject has no properties at all.
Upvotes: 0
Reputation: 12742
Please don't.
That's really bad form and will lead to nasty, hard to find, bugs.
Or if you do - do it with greatest of cares.
Read here for more: http://perfectionkills.com/extending-built-in-native-objects-evil-or-not/
Upvotes: 1