- Is there any way Date.toString to be againts current CultureInfo at least, or by some setting on the EcmaScriptComponnet
- Is there some tutotrial how to inherit EcmaScriptObject and implement functions and properties on it
- Can I extend .Net object in JavaScript engine with .prototype, how can do this
- All .Net objects has .ToString() is this equivalent of JavaScript object .toString(), how can do this
CS Code:
using RemObjects.Script.EcmaScript;
using System;
using System.Collections.Generic;
using System.Text;
namespace ToRemObjects
{
public class RemObjectsConsole
{
public RemObjectsConsole()
{ }
public void writeBoolean(bool v)
{
Console.WriteLine(v);
}
public void writeDateTime(DateTime v)
{
Console.WriteLine(v);
}
public void writeDouble(double v)
{
Console.WriteLine(v);
}
public void writeObject(EcmaScriptObject v)
{
Console.WriteLine(null == v ? “<>” : v.Class + “:” + v.ToString());
}
public void writeString(string v)
{
Console.WriteLine(null == v ? “<>” : v.ToString());
}
public DateTime getDateTime()
{
return default(DateTime);
}
public double getDouble()
{
return default(double);
}
public bool getBoolean()
{
return default(bool);
}
public string getString()
{
return string.Empty;
}
public void Execute(string sql, params object[] parameters)
{
//do someting…
string s = sql;
}
public double propDouble
{
get { return 100; }
set { double i = value; }
}
}
class Program
{
static void Main(string[] args)
{
using (var esc = new RemObjects.Script.EcmaScriptComponent())
{
object o = null;
esc.Include("test1", @"
function GlobalFunction(cc) {
var a;
cc.writeString(a);
cc.writeString(undefined);
cc.writeString(null);
cc.writeString(1.3);
cc.writeString(true);
cc.writeString(Number(1.5));
cc.writeString(new Boolean(true));
cc.writeString(new Number(1.5));
cc.writeString(new Date());// -> 01/08/2013 23:00:55 is there any way to be againts current CultureInfo at least, or by some setting on the EcmaScriptComponnet
// Date.toString ECMA Standart http://www.ecma-international.org/ecma-262/5.1/#sec-15.9 This function returns a String value. The contents of the String are implementation-dependent, but are intended to represent the Date in the current time zone in a convenient, human-readable form.
// Windows Script Host and Internet Explorer -> Tue Jan 8 22:21:04 UTC+0200 2013
// Google Chrome -> Tue Jan 08 2012 22:24:14 GMT+0200 (FLE Standard Time)
// FireFox -> Tue Jan 08 2013 23:14:28 GMT+0200 (FLE Standard Time)
}
function GlobalFunction2(cc) {
var a;
cc.writeDouble(‘aaa’);//exception -> double.NaN???
cc.writeDouble(a);// a is undefined and result to 0 is this right .NET has double.NaN for this
cc.writeDouble(undefined);// again undefined and result to 0 is this right .NET has double.NaN for this
cc.writeDouble(null);
cc.writeDouble(‘1.3’);
cc.writeDouble(true);
cc.writeDouble(false);
cc.writeDouble(Number(1.5));
cc.writeDouble(new Boolean(false));
cc.writeDouble(new Number(1.5));
}
function GlobalFunction3(cc) {
cc.writeBoolean(""""); exception
cc.writeBoolean(Number.NaN); // result to true but if(Number.NaN) is false
if (Number.NaN) {
cc.writeString(‘NaN:true’);
}
else {
cc.writeString(‘NaN:false’);
}
cc.propDouble = new Number(123.1);//can do this
//cc.writeDateTime(new Date()); //can do this
cc.writeDouble(new Date()); //can’t do
cc.writeString(‘Date.getFullYear:’ + cc.getDateTime().getFullYear()); // can’t do this , but can do cc.writeDateTime(new Date()), typeof(cc.getDateTime()) result to number
//cc.writeString(‘Number.toFixed:’ + cc.getDouble().toFixed(2)); can do
//cc.writeString(‘String.substr:’ + cc.getString().substr(0,2)); can do
var a;
cc.writeObject(a);// can do, but result to null not Undefined.Instace
cc.writeObject(undefined);// can do, but result to null not Undefined.Instace
cc.writeObject(null);
cc.writeObject({a: 1, b: ‘ss’});
cc.writeObject(1.3);// can’t do -> exception
cc.writeObject(false);// can’t do -> exception
cc.writeObject(Number(1.5));// can’t do -> exception
cc.writeObject(new Boolean(false));// can’t do -> exception
cc.writeObject(new Number(1.5));// can’t do -> exception
cc.writeObject(new Date());// can’t do -> exception
cc.writeObject(new Array());
}
");
RemObjectsConsole cc = new RemObjectsConsole();
o = esc.RunFunction(“GlobalFunction”, cc);
o = esc.RunFunction(“GlobalFunction2”, cc);
o = esc.RunFunction(“GlobalFunction3”, cc);
Console.ReadLine();
}
}
}
}