It works in a similar to Google Chrome way: whenever you press command+Q for the first time in Safari, you’re going to see a popover asking you to confirm Safari quitting by pressing command+Q again.
And if you press the command+Q again while the popover is still present, the Safari will quit as usual.