In this paper, as a generalization of derivation of a $B$-algebra, we introduce the notion of $f$-derivation and $(f,g)$-derivation of a $B$-algebra. Also, some properties of $(f,g)$-derivation of commutative $B$-algebra are investigated.