这段Javascript代码如何工作?

时间:2017-03-03 15:13:57

标签: javascript

我知道T是Twit的一个对象,并且可以从类中创建对象。但是从这个声明来看,T看起来像是由变量而不是类创建的。有人可以澄清吗?

    Dataset<Row> inputDS=spark.read().option("header", false).
            option("inferSchema",true).csv("data/irisAA.csv");
    inputDS.show(4);
    String colAname=inputDS.columns()[0];
    log.error(colAname);
    String colBname=inputDS.columns()[1];
    log.error(colBname);
    Dataset<Row> DSColA=inputDS.select(inputDS.col(colAname));
    DSColA.show(4);
    Dataset<Row> DSColB=inputDS.select(inputDS.col(colBname));
    DSColB.show(4);
    Dataset<Row> DSColAandColA=DSColA.withColumn("Addt_Column", inputDS.col(colAname));
    DSColAandColA.show(4);
    /*Dataset<Row> DSColAandColB=DSColA.withColumn("Addt_Column", inputDS.col(colBname));
    DSColAandColB.show(4); //THIS FAILS........STILL DON'T GET WHY */
    Dataset<Row>  DSColAwithIndex=DSColA.withColumn("df1Key", monotonically_increasing_id());
    DSColAwithIndex.show(4);
    Dataset<Row>  DSColBwithIndex=DSColB.withColumn("df2Key", monotonically_increasing_id());
    DSColBwithIndex.show(4);
    DSColAwithIndex.join(DSColBwithIndex).show(4);
    DSColA.join(DSColB).show(4);
    Dataset<Row> DSwithJoinofTwo=DSColAwithIndex.join(DSColBwithIndex, col("df1Key").equalTo(col("df2Key")), "inner");
    DSwithJoinofTwo.show(4);
    Dataset<Row> DSwithJointrimmed=DSwithJoinofTwo.drop(DSwithJoinofTwo.apply("df1Key")).drop(DSwithJoinofTwo.apply("df2Key"));
    DSwithJointrimmed.show(4); //JOINED DATASET FINALLY OF COLUMN A AND COLUMN B FROM SAME OR DIFF. DATASETS

4 个答案:

答案 0 :(得分:4)

JavaScript中的

function是第一类对象,可以像其他任何东西一样分配给变量。

答案 1 :(得分:0)

添加到其他答案的示例:

&#13;
&#13;
Imports System.Data
Imports System.Data.SqlClient

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim conn As String = ConfigurationManager.ConnectionStrings("Data Source=JOAOCOQUIM\SQLEXPRESS;Initial Catalog=Teste;Integrated Security=True").ConnectionString
        Dim connection As SqlConnection = New SqlConnection(conn)
        Dim sql As String = "Insert into [User] ([nome], [idade]) values (@nome, @idade)"
        Dim cmd As SqlCommand = New SqlCommand(sql, connection)
        cmd.Parameters.AddWithValue("@nome", TextBox1.Text)
        cmd.Parameters.AddWithValue("@idade", TextBox2.Text)


        connection.Open()
        cmd.ExecuteNonQuery()
        connection.Close()
    End Sub
End Class`
&#13;
&#13;
&#13;

答案 2 :(得分:0)

要添加@ DanielAWhite的准确答案,请考虑以下C代码:

int i;
if (x == y)
{
  i = 3;
}
else
{
  i = 5;
}

int i = x == y ? 3 : 5; 

例如,在C ++中,当您声明一个与上面的if类似的类时:它是一个语句。它不能绑定到变量。 JavaScript中的“类”更像三元表达式,它们可以分配给任意名称(即作为赋值的有效RValue)。

// valid ES 6 code

class Foo {
  constructor: function() {...}
}

var foo = new Foo();

// also valid and more-or-less equivalent:

var Foo = class {
  constructor: function() {...}
};

var foo = new Foo();

答案 3 :(得分:-5)

节点js上的Test.js文件

    var Test={
             testJson:function(){
                            return [
                                     {
                                      'nome'    :'Name'
                                     }
                               ]
                }
            }
module.exports=Test;

另一个文件

const {testJson} = require('Test.js'); //initialize

testJson();

//调用变量,如函数