Dogs that were loyal and affectionate got protection, food, and care from humans. They had babies that reinforced those traits, through the generations. Those that didn’t, stayed wild as wolves.
That said, go say hi to a pack of rez dogs or similar and you’ll see that dogs are predisposed to be socialized to humans, but aren’t intrinsically and automatically socialized to humans.
Latest Answers