Skip to content

Instantly share code, notes, and snippets.

@meh
Created October 4, 2011 19:17
Show Gist options
  • Save meh/1262513 to your computer and use it in GitHub Desktop.
Save meh/1262513 to your computer and use it in GitHub Desktop.
Adding methods to prototype
# 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