Created
October 4, 2011 19:17
-
-
Save meh/1262513 to your computer and use it in GitHub Desktop.
Adding methods to prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# even better, imho | |
class << `Document` | |
# this goes in the prototype, so it ends up being on `document` too | |
def root | |
`return self.documentElement` | |
end | |
end | |
class << `document` | |
# this goes in the object itself, so only available in `document` | |
def self.to_s | |
"document" | |
end | |
end | |
# better way? | |
class Document | |
native_constructor `Document` | |
def root | |
`return self.root;` | |
end | |
end | |
# awkward.. | |
Class.extend_native_prototype(`Document`) do | |
include Opal::Core | |
def root | |
`return self.root;` | |
end | |
end | |
Class.extend_native_object(`document`) do | |
def to_s | |
`return "document";` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment