The following two code snippets show how erode implementation in C++ compares to its equivalent OpenCV.js implementation.
      void cpp_erode(){

       Mat image, dst;
       image = imread("image.jpg", CV_LOAD_IMAGE_COLOR);

       // Create a structuring element
       int erosion_size = 6;
       Mat element = getStructuringElement(cv::MORPH_RECT,
                          cv::Size(2*erosion_size+1, 2 * erosion_size + 1),
                          cv::Point(erosion_size, erosion_size));

       // Apply erosion or dilation on the image

       namedWindow("Display window", CV_WINDOW_AUTOSIZE);
       imshow("Display window", image );

       namedWindow("Result window", CV_WINDOW_AUTOSIZE);
       imshow("Result window", dst);
      function js_erode(){
        var src = CV.matFromArray(getInput(), CV.8UC4);
        var dst = new CV.Mat();
        CV.cvtColor(src, src,
            CV.ColorConversionCodes.COLOR_RGBA2RGB.value, 0);

        // Create a structuring element
        var erosion_type = CV.MorphShapes.MORPH_RECT.value;

        var erosion_size = new CV.Size(2*Control.erosion_size+1,

        var element = CV.getStructuringElement(erosion_type, erosion_size);

        // Apply erosion or dilation on the image
        CV.erode(src, dst, element) ;
        show_image(dst, "canvas2");

        // Clean up