FAQ

On Thu, Jun 16, 2016 at 2:11 PM, Tong Sun wrote:
How to define my own function


func FindUrl() { return
goquery.Find(".thing").Find(".comments.may-blank").Attr("href"); }

so that the above code can be simplified as:

post_url, _ := doc.FindUrl()
In your own package, you can only define new functions, not new
methods. https://golang.org/ref/spec#Method_declarations says that
"the receiver base type...must be declared in the same package as the
method". Thus, you can write your FindUrl to be

FindUrl(doc)

but not

doc.FindUrl()

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 3 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 16, '16 at 4:12a
activeJun 18, '16 at 12:09a
posts3
users2
websitegolang.org

2 users in discussion

Tong Sun: 2 posts Nigel Tao: 1 post

People

Translate

site design / logo © 2021 Grokbase