JavaScript - Object.assign to Spread运算符

时间:2018-01-16 14:45:47

标签: javascript ecmascript-next

我用这个构造函数初始化我的组件:

this.$q = $q
this.$state = $state

简单等同于

    public  void SplitPDFByBookMark(string fileName)
    {
        string sInFile = fileName;
        var pdfReader = new PdfReader(sInFile);
        try
        {
            IList<Dictionary<string, object>> bookmarks = SimpleBookmark.GetBookmark(pdfReader);

            for (int i = 0; i < bookmarks.Count; ++i)
            {
                IDictionary<string, object> BM = (IDictionary<string, object>)bookmarks[i];
                IDictionary<string, object> nextBM = i == bookmarks.Count - 1 ? null : bookmarks[i + 1];

                string startPage = BM["Page"].ToString().Split(' ')[0].ToString();
                string startPageNextBM = nextBM == null ? "" + (pdfReader.NumberOfPages + 1) : nextBM["Page"].ToString().Split(' ')[0].ToString();
                SplitByBookmark(pdfReader, int.Parse(startPage), int.Parse(startPageNextBM), bookmarks[i].Values.ToArray().GetValue(0).ToString() + ".pdf", fileName);

            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    private void SplitByBookmark(PdfReader reader, int pageFrom, int PageTo, string outPutName, string inPutFileName)
    {
        Document document = new Document();
        using (var fs = new FileStream(Path.GetDirectoryName(inPutFileName) + '\\' + outPutName, System.IO.FileMode.Create))
        {
            try
            {
                using (var writer = PdfWriter.GetInstance(document, fs))
                {
                    document.Open();
                    PdfContentByte cb = writer.DirectContent;
                    //holds pdf data
                    PdfImportedPage page;
                    if (pageFrom == PageTo && pageFrom == 1)
                    {
                        document.NewPage();
                        page = writer.GetImportedPage(reader, pageFrom);
                        cb.AddTemplate(page, 0, 0);
                        pageFrom++;
                        fs.Flush();
                        document.Close();
                        fs.Close();

                    }
                    else
                    {
                        while (pageFrom < PageTo)
                        {
                            document.NewPage();
                            page = writer.GetImportedPage(reader, pageFrom);
                            cb.AddTemplate(page, 0, 0);
                            pageFrom++;
                            fs.Flush();
                            document.Close();
                            fs.Close();
                        }
                    }
                }
                //PdfWriter writer = PdfWriter.GetInstance(document, fs);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }

使用Spread运算符可以选择什么?

1 个答案:

答案 0 :(得分:1)

无。在使用文字语法创建新对象时,您只能使用扩展语法。使用构造函数时,不要这样做。

顺便说一下,有no spread "operator",对象扩展语法不是ES6的一部分。